Saturday, November 7, 2015

SQL注意细节

1. Cross Join 就是 Cartesian Product
    Natural Join 就是基于相同列名的Left Outer Join Right Outer Join 或者Inner Join

2. Count(列名) 会忽略NULL的情况, 它一定会返回一个0到无穷大之间的数,不会返回NULL.
    COUNT(*) 很特殊,它会记录NULL的情况。

3. JOIN 分为Equi-Join, Non-Equi-Join以及Inner Join 和Outer Join

    On Column Between A and B

4. SELECT TO_CHAR(SUM(ALL(SALARY)), '$9999.99') FROM EMPLOYEE;
    将数字转为字符格式。

5. Median AVG 会忽略NULL的情况。

6. Select Can only include Expressions in the select list that are defined at the same level of detail as each other.

7. When Group by is involved order by can only include group by columns.

8. Nest Aggregate Function can be up to 2 level deep.

9. Select Required
    from Required
    where Optional
    Group by Optional
    Having Optional
    Order By Optional

10. Having only take Group by Clause and Aggregate functions

11. Sub Query will return NULL if not found.

12. Without Group by sub query will return Single Value

13. Find all products with a price that’s greater than all of the products in the ‘Luxury’ category:              
SELECT * FROM PRODUCTS
    WHERE PRICE > ALL (SELECT PRICE FROM PRODUCTS
    WHERE CATEGORY = ‘Luxury’);

14. < > 表示不等于

15. A scalar subquery returns one row with one column.
      Scalar subquery expressions can ONLY be used in the following locations: SELECT AND WHERE

No comments:

Post a Comment