常用sql语句(遇到好的sql会继续添加)

分页sql:


单表查询
①select * from (select a.id,a.name,a.singer,a.special,rownum rn from songsInfo a order by id ) where rn > 0 and rn < 10;
②select * from (select t.*,rownum rn from (select a.id,a.name,a.singer,a.special from songsInfo a ) t order by id ) where rn > 0 and rn < 10;
多表查询
select *  from 
(
select t.*,rownum rn from
(
select a.id,a.name,b.name as singer,c.name as special from voiceInfo a, singerInfo b, specialInfo c where a.singer = b.id and a.special = c.id 
) t
 ) where rn > 0 and rn < 10;


修改 replace的使用(将描述中含有“制热”的改为“制冷”)
update sysConfig set description = replace (description , '制热', '制冷');


group by 的使用(查询同一张员工表中工资相同的员工详细信息)

select * from persons where salary in (select salary from persons group by salary having count(salary) > 1) order by salary


group by 的使用(查询当天采集时间的所有记录)

--这里的采集时间是varchar2类型的

select temperature,humidity,windvalue,sunvalue,COLLECTTIME from (
   select   temperature,  humidity, windvalue,sunvalue,

 to_char(to_date(da.collecttime,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') COLLECTTIME
        from 

da_temandhhum_info da,DA_DEVICE_INFO de 
        where da.deviceid=de.id and de.deviceposition=1 

and

 to_char(to_date(collecttime,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD') = to_char(sysdate,'YYYY-MM-DD')


        group by to_char(to_date(da.collecttime,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') order by COLLECTTIME)


说明:在使用group by 时,有一个规则需要遵守,即出现在select列表中的字段,如果没有在组函数中,那么必须出现在group by 子句中。

(select中的字段不可以单独出现,必须出现在group语句中或者在组函数中。)


oracle

获取表中前十条数据

select * from (select * from 表名) where rownum <=10;







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值