loading..
Ðóññêèé    English
17:07

Exercise #39 page 2

Solution 3.4.2. The same result gives solution which uses self-join:

Console
Execute
  1. SELECT DISTINCT o.ship
  2. FROM Outcomes AS o, Outcomes AS o2
  3. WHERE (o.result = 'damaged' OR
  4.        o2.result = 'damaged'
  5.        ) AND
  6.        o.battle <> o2.battle AND
  7.        o.ship = o2.ship;

Here is applied the join of Outcomes table with itself provided that ship is the same, but fights are different. Besides, the ship has been damaged in one of fights. As easy to see, there was no check of a battle in which the ship has been damaged for earlier date.


Bookmark and Share
Pages 1 2 3 4
Tags
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
month ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.