转群友一个关于显示了分组方式下问题!!!!
来源:互联网 发布:程序员联合开发昂 编辑:程序博客网 时间:2024/05/11 13:34
/**//*--------------------- 建立测试表-----------------------------------------------------------------------------------*/
CREATE TABLE [tx] (
[name] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
[num] [int] NULL ,
[col] [char] (2) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
/**//*--------------------插入记录-------------------------------------------------------------------------------------------*/
insert tx
select 'z',1,'z1' union all
select 'z',2,'z2' union all
select 'x',1,'x1' union all
select 'x',2,'x2' union all
select 'z',2,'z1' union all
select 'z',1,'z2' union all
go
/**//*--------------------显示出以 以name分组下,num 最大或最小的记录集----------------------------*/
select a.*
from tx a ,(select name,max(num) as num from tx group by name) as b ----------一个表和一个表的条件子集匹配
where a.name=b.name and a.num=b.num --------以上二者的条件
-------------------------------------------------------------
1,num可变成比较大小的任意数据类型如: datetime
CREATE TABLE [tx] (
[name] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
[num] [int] NULL ,
[col] [char] (2) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
/**//*--------------------插入记录-------------------------------------------------------------------------------------------*/
insert tx
select 'z',1,'z1' union all
select 'z',2,'z2' union all
select 'x',1,'x1' union all
select 'x',2,'x2' union all
select 'z',2,'z1' union all
select 'z',1,'z2' union all
go
/**//*--------------------显示出以 以name分组下,num 最大或最小的记录集----------------------------*/
select a.*
from tx a ,(select name,max(num) as num from tx group by name) as b ----------一个表和一个表的条件子集匹配
where a.name=b.name and a.num=b.num --------以上二者的条件
-------------------------------------------------------------
1,num可变成比较大小的任意数据类型如: datetime
朋友的方法:
declare @t table(name varchar(10),num int,col varchar(10))
insert into @t select 'z',1,'z1'
union all select 'z',2,'z2'
union all select 'x',3,'x1'
union all select 'x',9,'x2'
union all select 'e',4,'e1'
union all select 'e',15,'e2'
select *
from @t a
where exists --------exists的应用
(select 1 from @t where a.name=name group by name having a.num=max(num))---------having a.num=max(num),只找出分组中最大num记录
insert into @t select 'z',1,'z1'
union all select 'z',2,'z2'
union all select 'x',3,'x1'
union all select 'x',9,'x2'
union all select 'e',4,'e1'
union all select 'e',15,'e2'
select *
from @t a
where exists --------exists的应用
(select 1 from @t where a.name=name group by name having a.num=max(num))---------having a.num=max(num),只找出分组中最大num记录
- 转群友一个关于显示了分组方式下问题!!!!
- 关于正则表达式分组的一个问题
- 一个分组显示的sql
- 关于手机显示乱码问题,多谢了!
- 一个关于asp显示记录的问题
- 请教一个关于显示窗口的问题
- 一个关于顺序显示记录的问题!!!
- 关于网页显示的一个诡异问题
- 关于FLEX的一个显示小问题
- 一个关于变量数据显示的问题
- 一个排列组合的分组问题
- 请教一个分组求值问题
- 网上看到了一个关于黑客的练习方式
- 关于GridView的Group分组显示(downmoon)
- 今天碰到了一个tablayout的显示问题
- 一个关于WORD文档在网页中显示的问题!
- 一个关于WORD文档在网页中显示的问题!
- 一个关于WORD文档在网页中显示的问题!
- 博与专的矛盾与统一
- Visual Studio.Net 快捷键表“全局”快捷键
- 配置支持SSL的Tomcat
- openssl简介
- 一个加密与解密的实例
- 转群友一个关于显示了分组方式下问题!!!!
- ACE安装
- 手把手教您用winbinder来开发php的桌面应用程序[连载一:安装配置篇]
- 工作半年了!
- 内存管理(二)
- Oracle Profile 使用详解
- 使用STL中的泛型算法及函数对象
- user breakpoint called from code at 0x******
- 面试题集锦