doupingpeng7567 2012-04-10 19:46
浏览 231
已采纳

如何在php中获取最大日期数据

i have three tables..

SEEKER
seeker_nic--- username---request_fulfilled
111-----------ali--------YES
222-----------bilal------YES

second table is

DONOR
donor_nic---username----area
999----------Fahad-------UK
555----------SAJAD------USA
777---------HAMZA-------PK

third table is

STATUS
status-id---seeker_nic---donor_nic--requestfulfilled_by----request_fulfilled_date 
1 -------------111-------999---------- Fahad-------------2012/04/09
2 -------------111-------555---------- SAJAD-------------2012/05/15
3--------------222------777-----------HAMZA--------------2012/07/20

now i want this result for SEEKER (111) with latest data..

seeker_nic---username--- request_fulfilled---requestfulfilled_by----area---request_fulfilled_date
111-----------ali--------YES-----------------SAJAD-----------------USA--------2012/05/15

i am trying this query, this query shows rite seeker_nic, and requestfulfilled_date, but it shows wrong donor-nic, area and requestfulfilled_by...

SELECT seeker.seeker_nic, donor.donor_nic, donor.area, 
status.requestfulfilled_b , max( status.`request_fulfilled_date` ) AS request_fulfilled_date
FROM seeker
JOIN STATUS ON seeker.seeker_nic = status.seeker_nic
JOIN DONOR ON status.donor_nic = donor.donor_nic
WHERE seeker.username = '$uname'
GROUP BY status.`seeker_nic` 

i am getting ans like this....

seeker_nic---username--- request_fulfilled---requestfulfilled_by--------area--------request_fulfilled_date
111-----------ali---------------YES-----------------HAMZA--------------PK------------2012/05/15

plz help me.. :(

  • 写回答

3条回答 默认 最新

  • dqc18251 2012-04-10 20:19
    关注

    Try this:

    SELECT seeker.seeker_nic, donor.donor_nic, donor.area, status.requestfulfilled_by, status.request_fulfilled_date
    FROM seeker
    JOIN (
      SELECT seeker_nic, max(request_fulfilled_date) as last_date
      FROM status
      GROUP BY seeker_nic
    ) x ON x.seeker_nic = seeker.seeker_nic
    JOIN STATUS 
      ON x.seeker_nic = status.seeker_nic
      AND x.last_date = status.request_fulfilled_date
    JOIN DONOR 
      ON status.donor_nic = donor.donor_nic
    WHERE seeker.username = '$uname'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制