发表于 2018-10-21 13:57:34

SQL 基本语法记录

  SQL的基本语法
  1:select sno,sname from student where sage between 20 and 30   ----查询出20到30之间年纪的人员
  2:select sno,sname from student where sage is null   -----从student表中查询出年纪为空的人员
  3:select sno,sname from student where sname="cary" or sname="mina" or sname "amy"----查询出cary,mina,amy的学号和   名字
  还可以使用 select sno,sname from student where sname in('cary','mina','amy') 可以实现同样的功能
  select 部分
  1:AS 可以为字段重命名
  2:distinct   去重复值
  3:聚合函数()avg(),max(),min(),sum(),count()
  4:TOP5前5行数据select top 5 sno,sname from student
  5:Into   select top 5 into testtable from student把查询的TOP 5数据存到testtable表中,该testtable表存在于
  master数据库的表中
  select sno,sname,sage,sex into test table02 from student where 11------获取student表结构
  From 部分
  1:表重命名
  select bookname from book as t1,borrowbook as t2 where t1.id=t2.id----为book表重命名T1 borrowbook 为t2
  2:结合子查询
  select distinct bookname from book as t1 ,(select distinct bookid from borrowbook) as t2 where t1.bookid=t2.bookid
  where 部分
  1:数字 :=,>,,=,
页: [1]
查看完整版本: SQL 基本语法记录