- In the
GROUP BY
clause the 1
is a number literal value.
- In the
ORDER BY
clause the 1
refers to the the first term of the SELECT
clause.
If you do:
SELECT *
FROM (
SELECT COUNT(*)
FROM Employee
GROUP BY 1 -- A number literal
ORDER BY 1 DESC
)
WHERE ROWNUM = 1;
It is the same as:
SELECT *
FROM (
SELECT COUNT(*)
FROM Employee
GROUP BY NULL -- A NULL literal
ORDER BY 1 DESC
)
WHERE ROWNUM = 1;
or
SELECT *
FROM (
SELECT COUNT(*)
FROM Employee
GROUP BY 'ABC' -- A string literal
ORDER BY 1 DESC
)
WHERE ROWNUM = 1;
However,
SELECT *
FROM (
SELECT Months * Salary, COUNT(*)
FROM Employee
GROUP BY 1
ORDER BY 1 DESC
)
WHERE ROWNUM = 1;
Is not valid as 1
is a literal number value that you are grouping by whereas Months
and Salary
are column names that are in a GROUP BY
query but are not aggregated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…