Select b.dish_name as dish_1,
c.dish_name as dish_2,
d.dish_name as dish_3,
e.dish_name as dish_4,
f.dish_name as dish_5,
g.dish_name as dish_6,
h.dish_name as dish_7,
i.dish_name as dish_8,
j.dish_name as dish_9,
k.dish_name as dish_10,
from entries_table a
left join base_list as b on(a.dish_id_1 = b.dish_id)
left join base_list as c on(a.dish_id_2 = c.dish_id)
left join base_list as d on(a.dish_id_3 = d.dish_id)
left join base_list as e on(a.dish_id_4 = e.dish_id)
left join base_list as f on(a.dish_id_5 = f.dish_id)
left join base_list as g on(a.dish_id_6 = g.dish_id)
left join base_list as h on(a.dish_id_7 = h.dish_id)
left join base_list as i on(a.dish_id_8 = i.dish_id)
left join base_list as j on(a.dish_id_9 = j.dish_id)
left join base_list as k on(a.dish_id_10 = k.dish_id)
1条答案
按热度按时间o8x7eapl1#
你的table设计很复杂。您的条目表应如下所示:
user_ID, dish_ID, ranking, date, selection_ID
(如果有人在每个日期进行多个选择,则需要类似selection\u id的内容)在当前的设计中,可以使用包含所有菜肴的if子句。但根据菜品的多少那恐怕是太多的工作了。
但是,这应该对您有用:
我不知道你确切的列名。只要用你的列名替换我的列名,如果需要的话添加更多的列,就会得到你想要的结果。