抱歉错过了我的表格和数据:
0010066,32,Wicam,NotInterest,2014-02-01 0010066,32,Wicam,Discusing,2014-02-05 0010066,32,Wicam,Interest,2014-02-08 0010066,32,Wicam,Pending,2014-02-21 0010596,32,United,Interest,2014-02-08 0010606,32,SEACAM,NotInterest,2014-03-08 0040025,16,SkyView,Interest,2014-03-17
我使用下面的查询:
$ uer_id =' $ _ GET [USER_ID]&#39 ;; $备注=' $ _ GET [备注]&#39 ;; $ query = $ link->查询(" SELECT * FROM(SELECT * FROM tbreport,其中user_id =' $ uid'按日期排序DESC)tbreport GROUP BY comcode");
结果显示最后一条记录:
0010066,32,Wicam,Pending,2014-02-21
0010596,32,United,Interest,2014-02-08
0010606,32,SEACAM,NotInterest,2014-03-08
0040025,32,SkyView,Interest,2014-03-17
我需要的结果是什么
0010596,32,United,Interest,2014-02-08
0040025,32,SkyView,Interest,2014-03-17
当$ remark ='待定'应该如下所示
0010066,32,Wicam,Pending,2014-02-21
那我该怎么办呢? 谢谢,如果有任何疑问 萨利
答案 0 :(得分:1)
SELECT m1.* FROM tbreport m1 LEFT JOIN tbreport m2
ON (m1. comname = m2. comname AND m1.date < m2.date)
WHERE m2.date IS NULL and m1.remark='$remark';