分组取数据
来源:互联网 发布:做手机壁纸的软件 编辑:程序博客网 时间:2024/05/01 14:34
create table temp ( a_NAME nvarchar(10), B_NAME int)
insert into temp
select 'A ', 42
union select 'A ', 333
union select 'B ', 444
union select 'B ', 555
union select 'B ', 666
union select 'C ', 777
union select 'C ', 888
union select 'C ', 999
insert into temp select 'A ', 32
insert into temp select 'A ', 500
insert into temp select 'A ', 214
insert into temp select 'A ', 654
insert into temp select 'A ', 100
insert into temp select 'A ', 200
-- top 6
select a_NAME,B_NAME from temp a
where (select Count(1) from temp b where a.a_NAME=b.a_NAME and a.B_NAME <b.B_NAME ) <6
order by a_NAME,B_NAME desc
--次大
select a_NAME,min(B_NAME)
from(
select a_NAME,B_NAME from temp a
where (select Count(1) from temp b where a.a_NAME=b.a_NAME and a.B_NAME <b.B_NAME )=1) c
group by a_NAME
- 分组取数据
- 数据分组取最大值行
- SQL 取分组后前三条数据
- sql数据分组重复的取一条
- cross apply 实现取分组前几条数据
- sqlserver_分组排序取第一组数据
- Oracle分组取第一条数据
- Oracle分组取第一条数据
- sql 分组取最新的数据
- mysql 分组取第一条数据
- 先分组再排序 取特定数据
- MYSQL 分组取前N条数据
- oracle分组取前5条数据
- sql 分组取最新的数据sqlserver巧用row_number和partition by分组取top数据
- SQL 分组数据后 取每个分组的第一条数据(SQL Server)
- oracle分组取每组第一条数据
- sql取每个分组的第一行数据
- sqlserver2005巧用row_number和partition by分组取top数据
- 每天0点自动关机
- 如果你想在install shield2009中制作卸载程序
- JAVA中使用FTPClient上传下载
- 透明ToolTip
- 永不回头,不再妥协
- 分组取数据
- mudos的调试
- 烦恼
- 090721周二
- delphi共享文件夹
- Tomcat虚拟主机配置方案(域名解析)For Windows/Linux(最完全版)
- C#常见的几个技巧
- ABAP程序的性能优化啊.
- 怎样查看端口被占用情况