日期:2014-05-18 浏览次数:20678 次
--wuliaoName gongid select * from tb1 t where not exists (select 1 from tb1 where wuliaoName = t.wuliaoName and gongid = t.gongid and date > t.date)
------解决方案--------------------
select * from tb1 where exists (select wuliaoName, gongid,max(date) from tb1 group by wuliaoName ,gongid)
------解决方案--------------------
select id,wuliaoName,gongid,price,date from t where t.date=(select max(date) from t t1 where t.wuliaoName=t1.wuliaoName and t.gongid=t1.gongid)
------解决方案--------------------
select id,wuliaoName,gongid,price,date from tb1 t where date=(select max(date) from tb where t.wuliaoName=wuliaoName and t.gongid=gongid) ---字段可以加索引
------解决方案--------------------
好吧,脑抽了 上面两个是错误的 这个是最后版 ⊙﹏⊙b汗
select t1.wuliaoName,t1.gongid,t1.price,t1.date from tb1 t1, (select wuliaoName,gongid,max(date) as date from tb1 group by wuliaoName,gongid) t2 where t1.wuliaoName = t2.wuliaoName and t1.gongid = t2.gongid and t1.date = t2.date;
------解决方案--------------------