写出一个sql,从a表中查询出第50行到第80行记录

写出一个sql,从a表中查询出第50行到第80行记录,第1张

select top 80 * from a as a1

where not exists(select top 49 * from a as a2 where a1.ID=a2.ID)

sqlserver2000中:

select top 50 * from 表 where id not in (select top 29 id from 表)

sqlserver2005中:

select top 50 * from 表 except select top 29 * from 表

Oracle中:

select * from 表 whre rownum<=50 minus select * from 表 where rownum<=29

mysql中:

select * from 表 limit 30,50

select name,count(*) as 'Count' from a group by name where cust_no is not null

union

select name,0 as 'Count' from a group by name where cust_no is null

分开查再合并就是了 先查非0的 用count 和 group by

再查是0的 然后用union合并就是了

因为不确定cust_no为空的时候设置的是什么数据类型 这里的判断条件我用的是is null 根据实际可能要改下


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9908940.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存