SQL中如何查出各个客户最后一次进货日期及金额?谢谢!
如表A:riqikehujine20120101a100.0020120312b50.0020120408a200.0020120509c80.0020120620b10...
如表A:
riqi kehu jine
20120101 a 100.00
20120312 b 50.00
20120408 a 200.00
20120509 c 80.00
20120620 b 100.00
20120630 c 300.00
结果:
riqi kehu jine
20120408 a 200.00
20120620 b 100.00
20120630 c 300.00 展开
riqi kehu jine
20120101 a 100.00
20120312 b 50.00
20120408 a 200.00
20120509 c 80.00
20120620 b 100.00
20120630 c 300.00
结果:
riqi kehu jine
20120408 a 200.00
20120620 b 100.00
20120630 c 300.00 展开
10个回答
展开全部
select f. kehu, f.riqi , A.jine from ( select kehu, max(riqi) riqi from A group by kehu ) f, A where f.kehu = A.kehu and f.riqi = A.riqi
追问
jine没显示,请问要怎么加呢?谢谢
追答
我改了,应该能显示的
select f. kehu, f.riqi , A.jine from ( select kehu, max(riqi) riqi from A group by kehu ) f, A where f.kehu = A.kehu and f.riqi = A.riqi
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Select * From A inner join (select Kehu,Max(riqi) As riqi From A Group By kehu) b on b.kehu = a.kehu where a.riqi = b.riqi
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from A join (select kehu ,max(riqi) from A group by kehu) B ON A.kehu = B.kehu and
A.riqi = B.riqi
A.riqi = B.riqi
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from tableA t where not exists (select 1 from tableA where kehu=t.kehu and riqi>t.riqi)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from Table_1 where riqi in (select max(riqi) riqi from Table_1 group by kehu)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询