常用SQL句语格式积累.docxVIP

  • 5
  • 0
  • 约1.41万字
  • 约 13页
  • 2017-04-07 发布于四川
  • 举报
常用SQL句语格式积累

常用SQL语句格式积累??一、常用的语句格式积累:?Select top 3 * from class order by id desc 表示查询前3条的数据并且按降来排?select distinct 年龄 from class ?去除重复行的查询select top 2 * from class order by newid() 表示随便查询2行数据select * from class where 年龄=20 or 年龄=19 and 性别=男 表示先查询年龄等于19 并且是男的 在查询所有年龄等于20的人 ?先执行AND查询 再执行ORselect * from class where id not in (select id from class1) 表示查询表一中在表2中没有的数据select * from class where id between 1 and 5 表示查询1到5的数据select * from class where id not between 1 and 5 表示查询不是1到5的数据select * from class where 姓名like 刘% 表示查询刘开头的人select * from class where 姓名like %丹%查询包含丹的人select * from class where 姓名like [刘丹]%查询以刘或者以丹开头的数据select * from class where 姓名like [%刘丹]%查询包含丹或者刘的数据select * from class where 年龄like [^1-2]%查询数据不是以1到2之间开头的select * from class where 年龄like [^刘陈]% 查询不是以刘或者陈开头的数据select * from class where 工作地址is null 表示查询工作地址不是空值的数据select * from class where 工作地址is not null 查询不是空植的数据select * from class where id all(select id from class1)表示查询表2在表一中没有的ID数据select * from class where id = any(select id from class1) 查询表一中和表2相同的IDelect * from class where (性别not in (男))and (not (年龄between 18 and 21))?not语句的查询 在条件语句前面加上NOT?select top 3 * from ?class order by id 前面最三个数据use liudanselect top 3 * from ?class order by id desc 最后三个的数据select ltrim(rtrim(姓名)) from class 里面函数RTRIM代表删除结尾空格数据 外面函数 ltrim 删除前面空格的数据select 姓名+, as 姓名,lower(gege) as gege from class ? ?给姓名的每条数据加上 ,; 把gege 列转换为小写select 姓名+, as 姓名,upper(gege) as gege from class 后面函数把数据全部转换为大写select * from class where month(日期)=9 and year(日期)=1993 and day(日期)=9分别是三个函数 第一个是对指定的日期 月 ,年,日select 年龄-id as a from class 表示用每一行的数据用年龄-id得到的数据+ - * / 都可以用select sum(年龄) as a from class ?求和select * from class where 年龄(select avg(年龄) from class) ?求年龄大于平均值的数据select * from class where 年龄= (select max(年龄) from class) 求年龄最大的、select * from class where 年龄= (select min(年龄) from class) 年龄最小的人select count(*) from class 表中数据总条数select count(年龄) from class 查询年龄不为空的select sum(年龄) from class where 性别=男 得到性别为男的的总年龄数select 年龄,count(*) from class group by 年龄 ? ? ?表示对年龄进行汇总,就是说 对相同年龄

文档评论(0)

1亿VIP精品文档

相关文档