日期:2014-05-18 浏览次数:20561 次
create table a(账号 varchar(10),日期 varchar(10),余额 int) insert into a select '001','20110101',100 union all select '002','20110101',200 union all select '003','20110101',100 union all select '001','20110102',100 union all select '002','20110102',210 union all select '003','20110102',150 union all select '001','20110103',100 union all select '002','20110103',220 union all select '003','20110103',100 select * from a select 账号 from a where 日期 between '2011-01-01' and '2011-01-03' group by 账号 having max(余额)=min(余额) /* 001 */
------解决方案--------------------
if OBJECT_ID('tbl')is not null
drop table tbl
go
create table tbl(
账号 varchar(10),
日期 varchar(10),
余额 int)
insert into tbl
select '001','20110101',100 union all
select '002','20110101',200 union all
select '003','20110101',100 union all
select '001','20110102',100 union all
select '002','20110102',210 union all
select '003','20110102',150 union all
select '001','20110103',100 union all
select '002','20110103',220 union all
select '003','20110103',100
select 账号 from tbl where 日期 between '20110101' and '20110103'
group by 账号
having MAX(余额)=MIN(余额)
/*
结果表
账号
001
*/