sql语法

  1. 写出删除表中重复记录的语句 oracle

delete from people

where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) and rowid not in (select min(rowid) from people group by

    2. 写一条SQL,查询姓张学生中平均成绩大于75的学生信息
       select * from student where name in (select name from student where name like '张%' group
      by name having avg(score) > 75)
    3. order by 多条件排序
       ORDER子句按一个或多个(最多16个)字段排序查询结果,可以是升序(ASC)也可以是降序(DESC),缺省是升序。ORDER子句通常放在SQL  
语句的最后。 

ORDER子句中定义了多个字段,则按照字段的先后顺序排序: 

select * from tablename order by column1 desc, column2 asc, column3 desc; 

在column2中有'AAA','BBB'两种值。让AAA在前,BBB在后排序的情况: 

方法一 select * from tablename order by column1 desc,case column2 when 'AAA' then 0 when 'BBB' then 1 end,column3 desc; 

方法二 select * from tablename order by column1 desc,CHARINDEX(column2,'AAA,BBB') , column3 desc
     4. case when 语法
          1。
 
 
    1. select name,  
    2.  case   
    3.         when birthday<'1981' then 'old'  
    4.         when birthday>'1988' then 'yong'  
    5.         else 'ok' END YORN  
    6. from lee; 

2。

 
 
    1. select NAME,  
    2.  case name  
    3.      when 'sam' then 'yong'  
    4.         when 'lee' then 'handsome'  
    5.         else 'good' end  
    6. from lee; 

当然了case when语句还可以复合

3。

 
 
    1. select name,birthday,  
    2.  case   
    3.      when birthday>'1983' then 'yong'  
    4.         when name='lee' then 'handsome'  
    5.         else 'just so so ' end  
    6. from lee;  
    7.  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值