SQL
SQL
Aggregated functions:
COUNT([Attribute]): Returns the number of values in the attribute.
SUM([Attribute]): Returns the sum of all values in the attribute.
MIN([Attribute]): Returns the minimum value in the attribute.
MAX([Attribute]): Returns the maximum value in the attribute.
AVG([Attribute]): Returns the average of the values in the attribute.
DISTICT can be applied to the attribute of the aggregate functions COUNT, SUM,
and AVG. It has no effect on MAX and MIN. For COUNT, unless DISTICT is used,
any valid attribute or * can be entered as the result will always be the same.
Repeat the key part for each pair of tables being combined (2 tables, 1
key. 3 tables, 2 keys. Etc.).
LEFT OUTER JOIN will also include Null values on the [Table 2] part of the
resulting table, which are caused when tuples from [Table 1] can’t be
matched to any tuple from [Table 2] via [Key 1].
Division:
Division in SQL works by taking a list of 2 attributes (X and Y) from one table
(T1), and a list of one of the 2 attributes (X) as another table (T2). We then group
each X attribute in T1 by their Y value and then we compare the X of each group
in T1 with the X in T2. The end result is a table that lists the Y of each group in T1
that had all the X values in T2
(SELECT [Attribute] FROM [Table 1])
MINUS
SELECT [Attribute] FROM (
(SELECT * FROM (SELECT [ID] FROM [Table 1]), [Table 2])
MINUS
(SELECT * FROM [Table 1]))
SELECT DISTINCT [Attribute 1]
FROM [Table 1]
WHERE [Attribute 1] NOT IN (
SELECT DISTINCT [Attribute 1]
FROM ((SELECT DISTINCT [Attribute 1] FROM
[Table 1]) AS T, [Table 2]
WHERE ([Attribute 1], [Attribute 2]) NOT IN
(SELECT * FROM [Table 1])
)