Thursday, December 22, 2011

Some rules about SQL

A GROUP BY clause must be included into SELECT statement, which use nested aggregate functions. Therefore, SELECT MAX(something) without GROUP BY clause is correct. But SELECT COUNT(AVG(something)) must have GROUP BY clause.

Columns listed in SELECT statement except included in group functions and columns listed in ORDER BY clause additionally MUST BE included in GROUP BY clause.

Any column alias can be used in an ORDER BY clause, including aliases in double quotes. For example:
SELECT a "Column A", b "Column B"
FROM temp_table
ORDER BY "Column B";


Simple view: 1) only one base table (or view); 2) no groups of data; 3) no functions; 4) welcome to DML always.

No DELETE through a view which include: 1) group function; 2) GROUP BY; 3) DISTINCT; 4) ROWNUM. Users can delete rows through a view which contain expressions.
No UPDATE through a view with DELETE restrictions and which include: 1) expressions.
No INSERT through a view with UPDATE restrictions and which NOT include: 1) columns that defined with NOT NULL option in the base table.

No comments:

Post a Comment