• MySQL之select简单使用


    Select * from table_name

    Select column_name_1,column_name_2 from table_name

     

    Select * from student where 姓名=‘刘婷’and 所在班级=2

    Select * from student where 成绩 between 90 and 100

    Select * from student where 姓名 like ‘刘%’

    Select * from student where 备注 is NOT NULL

     

    Select TOP 5 * from student

     

    Select column_name AS column_alias from table_name

     

    Select * from student order by 成绩 DESC

    Select * from student order by 成绩 ASC

     

    Select SUM(成绩) 总成绩 from student

    Select AVG(成绩) 平均成绩 from student

    Select MAX(成绩) 最高分,MIN(成绩) 最低分 from student

    Select COUNT(*) 总行数 from student

     

    Select 所在班级,SUM(成绩) AS 总成绩 from student GROUP BY 所在班级

             查询student表中每个班级的总成绩

    Select 所在班级,SUM(成绩) AS 总成绩 from student GROUP BY 所在班级 HAVING SUM(成绩)>200

             查询student表中总成绩大于200的班级

     

    Select * into student_bak from student

             将student表的数据插入到新表student_bak中

    Select * into student_2 from student WHERE 所在班级=2

             将student表中2班的学生信息保存到表student_2中

     

    左连接(A表全部显示,B表显示同A里相同的部分)

    Select A.name 姓名A,A.school 学校A,B.name 姓名B,job 职业B from A left join B on A.name=B.name

    右连接(B表全部显示,A表显示同B里相同的部分)

    Select A.name 姓名A,A.school 学校A,B.name 姓名B,job 职业B from A right join B on A.name=B.name

    内连接(显示AB表姓名相同的部分)

    Select A.name 姓名A,A.school 学校A,B.name 姓名B,job 职业B from A inner join B on A.name=B.name

    外连接(显示AB表全部的信息,其他为NULL)

    Select A.name 姓名A,A.school 学校A,B.name 姓名B,job 职业B from A full join B on A.name=B.name

  • 相关阅读:
    Fiddler: Creation of interception certificate failed.
    ip地址检查正则表达式 兼容ipv4,ipv6
    母版页与子页的启动过程
    erlang 读取confg文件异常 could not start kernel pid error in config file
    转义字符 显示形式 转换成 实际形式 \\n to \n
    How to use epoll? A complete example in C
    Lex & Flex 词法分析器实践(未完,持续更新)
    我理解的爱情———柳智宇 (转载)
    Learning by doing 系列文章概述
    锁与RCU数据共享机制
  • 原文地址:https://www.cnblogs.com/chy-op/p/10055499.html
Copyright © 2020-2023  润新知