select * from 表 a where exists (select 1 from (select 客户,max(日期) 日期 from 表 group by 客户) b where a.客户=b.客户 and a.日期=b.日期)
select 客户,max(日期) from 客户资金表 group by 客户;
create table lt (a char(4), b datetime) select * from lt --insert lt values('F004','2002-01-05') select * from lt a where exists (select 1 from (select a,max(b) b from lt group by a) b where a.a = b.a and a.b=b.b)
select 客户,max(日期) as rq into #t from 客户资金表 group by 客户 select 客户,日期 ,资金 from 客户资金表 k inner join #t t on k.客户=t.客户 and k.日期=t.rq
select * from table1 where (客户 , 日期 ) in (select 客户 , max( 日期 ) from table1 group by 客户 ,日期 )
select * from table1 where 日期 =(select max(a.日期) from table1 a where a.客户=table1.客户)
select * from 客户资金表 as a where a.日期 in(select max(日期) from 客户资金表 where a.客户=客户 group by 客户)
select * from T a where 日期 =(select max(日期) from T where 客户=a.客户)
select d.* from #tt d, ( select 客户 ,max( 日期 ) 日期 from #tt group by 商品名 ) c where d.客户 =c.客户 and d. 日期 =c. 日期
select a.*,b.资金 from (select 客户,max(日期) ord from test group by 客户) a, test b where b.客户=a.客户 and b.日期=a.日期
又弄错了一个地方。 select a.*,b.资金 from (select 客户,max(日期) 日期 from test group by 客户) a, test b where b.客户=a.客户 and b.日期=a.日期
(a char(4), b datetime)
select * from lt
--insert lt values('F004','2002-01-05')
select * from lt a
where exists (select 1 from
(select a,max(b) b from lt group by a) b
where a.a = b.a and a.b=b.b)
select 客户,日期 ,资金 from 客户资金表 k
inner join #t t on k.客户=t.客户 and k.日期=t.rq
in (select 客户 , max( 日期 ) from table1 group by 客户 ,日期 )
日期 =(select max(a.日期) from table1 a where a.客户=table1.客户)
where a.日期 in(select max(日期) from 客户资金表 where a.客户=客户 group by 客户)
from T a
where 日期 =(select max(日期)
from T
where 客户=a.客户)
( select 客户 ,max( 日期 ) 日期 from #tt group by 商品名 ) c
where d.客户 =c.客户 and d. 日期 =c. 日期
select a.*,b.资金 from (select 客户,max(日期) ord from test group by 客户) a,
test b where b.客户=a.客户 and b.日期=a.日期
select a.*,b.资金 from (select 客户,max(日期) 日期 from test group by 客户) a,
test b where b.客户=a.客户 and b.日期=a.日期