0

私は3つのテーブルを持っています..

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

2番目のテーブルは

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

3番目のテーブルは

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

今、私はSEEKER(111)の最新データでこの結果が欲しい..

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

このクエリを試しています。このクエリは rite seeker_nic と requestfulfilled_date を示していますが、間違ったドナー NIC、エリア、および 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` 

私はこのようなアンズを得ています....

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

助けてください.. :(

4

3 に答える 3

2

これを試して:

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'
于 2012-04-10T20:19:40.913 に答える
2

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
于 2012-04-10T20:35:02.063 に答える
0
SELECT x.seeker_nic, y.username, y.request_fulfilled,
       x.requestfulfilled_by, z.area, x.request_fulfilled_date
FROM status x, seeker y, donor z
WHERE x.seeker_nic=y.seeker_nic AND y.seeker_nic=111 AND z.donor_nic=x.donor_nic;
于 2012-04-10T20:27:15.890 に答える