我有一個表artefact_combos:MySQL的:選擇組合中的項目所需的數量所擁有的所有組合
id name points study_time
3 Climate Priority Oven 13333 13333
和另一artefact_combo_items指定項目,使所需的那些項目的數量artefact_combo:
id artefact_combo_id thing_id number
138 3 809 2
139 3 798 3
141 3 583 1
接着的的第三表user_thing:
SELECT *
FROM `user_thing`
WHERE (thing_id =809
OR thing_id =798
OR thing_id =583) WHERE user_id=4
LIMIT 0 , 30
id user_id thing_id
3229 4 583
17756 4 583
因此,在這種情況下,用戶4具有> =所需的項目數583,但沒有其他需要的項目數,所以我期待和空的結果。如果結果是:
id user_id thing_id
3229 4 583
156 4 583
17756 4 789
17856 4 789
67756 4 789
122323 4 809
434 4 809
我想要一個結果集,如:
id name points study_time
3 Climate Priority Oven 13333 13333
我試圖構建一個MySQL查詢,將得到的artefact_combos列表:某一特定user_id具有所需數量artefact_combo_items爲artefact_combos。
我最近的最後4小時嘗試是:
SELECT foo.thing_id,
count(user_thing.id)
FROM
(SELECT
a.name,
c.id,
c.artefact_combo_id,
c.thing_id,
c.number
FROM artefact_combo_items AS c
INNER JOIN user_thing AS b ON b.id = c.thing_id
INNER JOIN artefact_combos AS a ON a.id = c.artefact_combo_id
ORDER BY a.name DESC) AS foo, user_thing WHERE user_thing.id = foo.thing_id
我的道歉,如果這個問題太具體或嚴重解釋;我可能比我準備啃咬的還要多。任何想法,提示或教導將非常感激。謝謝!
你似乎對第三表沒有主鍵,這可能使事情不相稱難以 – Strawberry
查詢不符合您的架構。也許你可以使用這個網站http://sqlfiddle.com/創建一個最小的例子,並告訴我們,你期望得到什麼結果 –
@Strawberry謝謝 - 我試圖改變這個問題,以更具體地說明我是什麼實際上面對。 –