1

次の結果セットからpidがNULLであるレコードが必要です。

pid    users_fee_schedule_students_name users_fee_schedule_students_uid

8       users                   6           MBA in IT   1   1337097600  3   6   user    250000
9       users                   6           MBA in IT   2   1337184000  3   7   user    250000
NULL    ashuser                 277         MBA in IT   1   1337097600  3   6   user    250000
NULL    ashuser                 277         MBA in IT   2   1337184000  3   7   user    250000
10      sriuser                 66          MBA in IT   1   1337097600  3   6   user    250000
NULL    sriuser                 66          MBA in IT 

上記の結果セットを取得するためのSQLクエリは

SELECT FSP.pid,  users_fee_schedule_students.name AS users_fee_schedule_students_name, users_fee_schedule_students.uid AS users_fee_schedule_students_uid, fee_schedule.name AS fee_schedule_name, fee_schedule_instalments.instalment_no AS fee_schedule_instalments_instalment_no, fee_schedule_instalments.payable_by AS fee_schedule_instalments_payable_by, fee_schedule.fid AS fid, fee_schedule_instalments.iid AS fee_schedule_instalments_iid, 'user' AS field_data_field_school_course_user_entity_type, SUM(fee_schedule_instalments.amount) AS fee_schedule_instalments_amount
FROM 
ic_fee_schedule AS fee_schedule
LEFT JOIN ic_fee_schedule_students AS fee_schedule_students ON fee_schedule.fid = fee_schedule_students.fid
LEFT JOIN ic_users AS users_fee_schedule_students ON fee_schedule_students.uid = users_fee_schedule_students.uid
LEFT JOIN ic_fee_schedule_instalments AS fee_schedule_instalments ON fee_schedule.fid = fee_schedule_instalments.fid
LEFT JOIN ic_fee_schedule_payments AS FSP ON fee_schedule.fid = FSP.fid AND fee_schedule_students.uid = FSP.uid AND fee_schedule_instalments.iid = FSP.iid
WHERE (( (fee_schedule.fid = '3' ) ))
GROUP BY users_fee_schedule_students_name, users_fee_schedule_students_uid, fee_schedule_name, fee_schedule_instalments_instalment_no, fee_schedule_instalments_payable_by, fid , fee_schedule_instalments_iid

LEFT JOIN ic_fee_schedule_payments AS FSPは、他のタイプの参加で変更する必要があると思います。それをチェックしています.....

よろしくお願いします。

4

2 に答える 2

2

これを試しました:

SELECT * FROM TableA
LEFT OUTER JOIN TableB
ON TableA.name = TableB.name
WHERE TableB.id IS null

表Aのみでレコードのセットを生成し、表Bでは生成しないようにするには、同じ左外部結合を実行し、where句を使用して不要なレコードを右側から除外します。

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

于 2012-05-30T07:01:25.177 に答える
0

FSPで左結合を実行しているので、WHERE句「ANDFSP.pidISNULL」を追加するだけでよいと思います。

これを試して:

SELECT FSP.pid,  users_fee_schedule_students.name AS users_fee_schedule_students_name, users_fee_schedule_students.uid AS users_fee_schedule_students_uid, fee_schedule.name AS fee_schedule_name, fee_schedule_instalments.instalment_no AS fee_schedule_instalments_instalment_no, fee_schedule_instalments.payable_by AS fee_schedule_instalments_payable_by, fee_schedule.fid AS fid, fee_schedule_instalments.iid AS fee_schedule_instalments_iid, 'user' AS field_data_field_school_course_user_entity_type, SUM(fee_schedule_instalments.amount) AS fee_schedule_instalments_amount
FROM ic_fee_schedule AS fee_schedule
LEFT JOIN ic_fee_schedule_students AS fee_schedule_students ON fee_schedule.fid = fee_schedule_students.fid
LEFT JOIN ic_users AS users_fee_schedule_students ON fee_schedule_students.uid = users_fee_schedule_students.uid
LEFT JOIN ic_fee_schedule_instalments AS fee_schedule_instalments ON fee_schedule.fid = fee_schedule_instalments.fid
LEFT JOIN ic_fee_schedule_payments AS FSP ON fee_schedule.fid = FSP.fid AND fee_schedule_students.uid = FSP.uid AND fee_schedule_instalments.iid = FSP.iid
WHERE fee_schedule.fid = '3'
AND FSP.pid IS NULL
GROUP BY users_fee_schedule_students_name, users_fee_schedule_students_uid, fee_schedule_name, fee_schedule_instalments_instalment_no, fee_schedule_instalments_payable_by, fid , fee_schedule_instalments_iid
于 2012-05-30T07:51:22.023 に答える