Hi Vadim
Just bought your book and reading chapter 1 counting. I have a minor quibble about the scalar subquery corresponding to the predecessor example
I ran your examples on the northwind sample database using the web interface on w3 schools http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
and replaced their query versions of your example queries on their database. It worked a treat. But my version of the scalar subquery
SELECT t.ContactName t, t.CustomerID id,
(SELECT count(*) from Customers tt WHERE tt.CustomerID < t.CustomerId) seq
FROM Customers t
GROUP BY t.CustomerID
;
is not exactly the same query as you gave – no #, and <= is replaced with <
But it also return zero as a result which did not occur in my version of the predecessor query
SELECT t.ContactName t, t.CustomerID id, Max(tt.CustomerID) predecessor FROM Customers t, Customers tt WHERE tt.CustomerID < t.CustomerID
GROUP BY t.CustomerID
;
thanks
Dave