1. SELECT from WORLD Tutorial - SQLZOO
    2. https://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial
    3. # 选择所有数据 数据多要加条件限制
    4. select * from
    5. # 字段别名 as 可有可无 ,选择多列 用逗号隔开
    6. select name as 国家名, continent 大洲, population 人口 from world
    7. # 数据去重 distinct ;
    8. # 如果select distinct后有多个字段名时,是对重复的行数据进行去重
    9. # 注意distinct在select中使用时,只能加在select后而不是字段名前
    10. select distinct continent from world
    11. select count(distinct continent) from world
    12. count(distinct 字段) 去重计数

    总结

    1. 基础语法
    2. select 字段名 from 表名称
    3. 别名语法
    4. select 字段名 as 别名 from 表名称
    5. 注意:as可以省略
    6. 查询多列
    7. select 字段名1, 字段名2, 字段名3 from 表名称
    8. 查询所有列
    9. select * from 表名称
    10. 数据去重
    11. select distinct 字段名 from 表名称
    12. select中的计算字段
    13. select 字段名,计算字段 from 表名称
    14. 注意:计算字段中的算式所涉及的 字段名必须是表格中包含的,或者算式本身可以独立运算
    15. 标准语法
    16. select 字段名
    17. from 表格名
    18. where 条件代码
    19. 运算符查询语法
    20. select 字段名
    21. from 表名称
    22. where 字段名 运算符
    23. 模糊查询语法
    24. select 字段名
    25. from 表名称
    26. where 字段名 like '通配符+字符'
    27. 使用多条件查询
    28. select 字段名
    29. from 表名称
    30. where 条件代码1 and|or 条件代码2
    31. GROUP BY,顾名思义:根据...分组,在SQL中常根据指定字段分组(指定字段内容相同是为一组),然后针对组进行相关操作
    32. WHEREHAVING的区别在于:
    33. where 子句的作用是对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,where条件中不能包含聚组函数,使用where条件过滤出特定的行。
    34. having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件过滤出特定的组,也可以使用多个分组标准进行分组。
    35. Invalid use of group function即“集函数的无效用法”
    36. 错句示例:SELECT sname AS '优秀学生姓名',AVG(score) as '平均成绩' FROM `grade_info` WHERE AVG(score)>90 GROUP BY sno;
    37. 正确写法:SELECT sname AS '优秀学生姓名',AVG(score) as '平均成绩' FROM `grade_info` GROUP BY sno HAVING AVG(score) > 90 ;
    38. select 字段名1
    39. from 表格名
    40. [where 条件代码]
    41. [group by 字段名1]
    42. [having 条件代码]
    43. order by 字段名 asc|desc

    运算符
    image.png
    通配符
    image.png