Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中获取最长日期的数据_Php_Mysql_Sql - Fatal编程技术网

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

如何在php中获取最长日期的数据,php,mysql,sql,Php,Mysql,Sql,我有三张桌子 SEEKER seeker_nic--- username---request_fulfilled 111-----------ali--------YES 222-----------bilal------YES 第二张桌子是 DONOR donor_nic---username----area 999----------Fahad-------UK 555----------SAJAD------USA 777---------HAMZA-------PK STATUS s

我有三张桌子

SEEKER
seeker_nic--- username---request_fulfilled
111-----------ali--------YES
222-----------bilal------YES
第二张桌子是

DONOR
donor_nic---username----area
999----------Fahad-------UK
555----------SAJAD------USA
777---------HAMZA-------PK
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
第三张桌子是

DONOR
donor_nic---username----area
999----------Fahad-------UK
555----------SAJAD------USA
777---------HAMZA-------PK
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
现在,我想要搜索者(111)的最新数据的结果

seeker_nic---username--- request_fulfilled---requestfulfilled_by----area---request_fulfilled_date
111-----------ali--------YES-----------------SAJAD-----------------USA--------2012/05/15
我正在尝试此查询,此查询显示rite seeker_nic和RequestCompleted_日期,但显示错误的捐赠nic、区域和RequestCompleted_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` 
我得到了这样的答案

seeker_nic---username--- request_fulfilled---requestfulfilled_by--------area--------request_fulfilled_date
111-----------ali---------------YES-----------------HAMZA--------------PK------------2012/05/15
请帮助我(

试试这个:

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'
试试这个:

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'

如果需要为某个特定用户选择最新日期,则不需要
GROUP BY
子句:

SELECT
    status.request_fulfilled_date, # status.requestfulfilled_by,
    seeker.seeker_nic, seeker.username, seeker.request_fulfilled,
    donor.donor_nic, donor.username, donor.area 
FROM      status
LEFT JOIN seeker ON status.seeker_nic = seeker.seeker_nic
LEFT JOIN donor  ON status.donoc_nic  = donor.donor_nic
WHERE seeker.username = 'ali'
ORDER BY status.request_fulfilled_date DESC
LIMIT 1

如果需要为某个特定用户选择最新日期,则不需要
GROUP BY
子句:

SELECT
    status.request_fulfilled_date, # status.requestfulfilled_by,
    seeker.seeker_nic, seeker.username, seeker.request_fulfilled,
    donor.donor_nic, donor.username, donor.area 
FROM      status
LEFT JOIN seeker ON status.seeker_nic = seeker.seeker_nic
LEFT JOIN donor  ON status.donoc_nic  = donor.donor_nic
WHERE seeker.username = 'ali'
ORDER BY status.request_fulfilled_date DESC
LIMIT 1

“我正在尝试此查询”-您没有将您的查询放在您的问题上,这将是一个很好的了解。我只是忘记了..我现在添加了查询..常见的<代码>按日期排序\u列描述限制1?这又是一个相同的问题..它可以找到rite date和rite seeker \u nic,,但它显示了其他用户的请求完成人和区域:(请帮助…“我正在尝试此查询,”-您没有将您的查询放在您的问题上,这很好知道。我只是忘记了。我现在添加了查询…常见的
按日期排序\u列描述限制1
?这是同样的问题。它可以查找rite date和rite seeker \u nic,但它显示了其他用户的请求完成人和区域:(请帮助…你已经解决了我的问题…非常感谢@bobvienholt:)你已经解决了我的问题…非常感谢@bobvienholt:)这个查询也可以根据我的要求工作…thnx@Salman A:)这个查询也可以根据我的要求工作…thnx@Salman A:)