MySQL: Select all Combinations where required number of Combination Items is owned -
i have table artefact_combos:
id name points study_time 3 climate priority oven 13333 13333 and artefact_combo_items specifying items, , number of items required make artefact_combo:
id artefact_combo_id thing_id number 138 3 809 2 139 3 798 3 141 3 583 1 then third table of user_thing:
select * `user_thing` (thing_id =809 or thing_id =798 or thing_id =583) user_id=4 limit 0 , 30 id user_id thing_id 3229 4 583 17756 4 583 so in case user 4 has >= required number of item number 583, none of other required items, i'd expect , empty result. if result was:
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 i'd result set like:
id name points study_time 3 climate priority oven 13333 13333 i'm trying construct mysql query derive list of artefact_combos particular user_id has required number of artefact_combo_items artefact_combos.
my recent attempt of last 4 hours has been:
select foo.thing_id, count(user_thing.id) (select a.name, c.id, c.artefact_combo_id, c.thing_id, c.number artefact_combo_items c inner join user_thing b on b.id = c.thing_id inner join artefact_combos on a.id = c.artefact_combo_id order a.name desc) foo, user_thing user_thing.id = foo.thing_id my apologies if question specific or badly explained; may have bitten off more i'm ready chew yet. thought, hints or teaches appreciated. thanks!
i query combo-user not having missing items:
select ac.* , u.id user_id artefact_combos ac join ( select distinct user_id id user_thing ) u not exists( select 1 artefact_combo_items aci left join ( select user_id , thing_id , count(1) cnt user_thing ut group user_id , thing_id ) ui on ui.thing_id = aci.thing_id aci.artefact_combo_id = ac.id , ( ui.user_id null or ( ui.user_id = u.id , ui.cnt < aci.number ) ) )
Comments
Post a Comment