select * from tablename where 发生日期=(select max(发生日期) from tablename where 操作工号=@操作工号)
select 操作工号,用户名,max(发生日期) from your_table group by 操作工号,用户名
select * from tablename a where 发生日期=(select max(发生日期) from tablename b where a.操作工号=b.操作工号)
To老兄psxfghost(哈哈) : 你的语句不行,会有重复的值
select a.* from table a, (select 用户名,操作工号,max(发生日期) 发生日期 from table group by 用户名,操作工号) b where a.用户名=b.用户名 and a.操作工号=b.操作工号 and a.发生日期=b.发生日期
select * from yourtable A where 发生日期=(select top 1 发生日期 from yourtable B where A.操作工号=B.操作工号 order by 发生日期 desc)
我的表结构:发生日期,用户名,消费额,操作工号 我想取得某操作工号所操作的用户名最近消费额的结果Select A.* from Table A inner join (Select 操作工号,用户名,Max(发生日期) From Table Group By 操作工号,用户名) B on A.操作工号 = B.操作工号 and a.用户名 = b.用户名
你的语句不行,会有重复的值
(select 用户名,操作工号,max(发生日期) 发生日期 from table group by 用户名,操作工号) b
where a.用户名=b.用户名 and a.操作工号=b.操作工号 and a.发生日期=b.发生日期
B where A.操作工号=B.操作工号 order by 发生日期 desc)
我想取得某操作工号所操作的用户名最近消费额的结果Select A.* from Table A
inner join
(Select 操作工号,用户名,Max(发生日期)
From Table
Group By 操作工号,用户名) B
on A.操作工号 = B.操作工号 and a.用户名 = b.用户名