SQL-basics

SQL 一些常用的查询语句用法

SQL-basics_第1张图片
SQL-basics_第2张图片

SQL 中的聚合函数

SQL-basics_第3张图片

SQL 中的子查询

SQL 使用实例

SELECT F_NAME , L_NAME
FROM EMPLOYEES
WHERE ADDRESS LIKE ‘%Elgin,IL%’;

SELECT F_NAME , L_NAME
FROM EMPLOYEES
WHERE B_DATE LIKE ‘197%’;

SELECT *
FROM EMPLOYEES
WHERE (SALARY BETWEEN 60000 AND 70000) AND DEP_ID = 5;

SELECT F_NAME, L_NAME, DEP_ID
FROM EMPLOYEES
ORDER BY DEP_ID;

SELECT F_NAME, L_NAME, DEP_ID
FROM EMPLOYEES
ORDER BY DEP_ID DESC, L_NAME DESC;

SELECT D.DEP_NAME , E.F_NAME, E.L_NAME
FROM EMPLOYEES as E, DEPARTMENTS as D
WHERE E.DEP_ID = D.DEPT_ID_DEP
ORDER BY D.DEP_NAME, E.L_NAME DESC;

SELECT DEP_ID, COUNT(*)
FROM EMPLOYEES
GROUP BY DEP_ID;

SELECT DEP_ID, COUNT(*), AVG(SALARY)
FROM EMPLOYEES
GROUP BY DEP_ID;

SELECT DEP_ID, COUNT(*) AS “NUM_EMPLOYEES”, AVG(SALARY) AS “AVG_SALARY”
FROM EMPLOYEES
GROUP BY DEP_ID;

SELECT DEP_ID, COUNT(*) AS “NUM_EMPLOYEES”, AVG(SALARY) AS “AVG_SALARY”
FROM EMPLOYEES
GROUP BY DEP_ID
ORDER BY AVG_SALARY;

SELECT DEP_ID, COUNT() AS “NUM_EMPLOYEES”, AVG(SALARY) AS “AVG_SALARY”
FROM EMPLOYEES
GROUP BY DEP_ID
HAVING count(
) < 4
ORDER BY AVG_SALARY;

你可能感兴趣的:(SQL,sql)