我有这个问题:
SELECT *, COUNT(item.sel_item_id) AS 'Count'
FROM item
GROUP BY item.sel_item_table, item.sel_item_id, item.gold
有了这个结果:
SEL_ITEM_TABLE SEL_ITEM_ID
pf_gem 2 ...
pf_gem 4 ...
pf_gem 3 ...
pf_weapons 4 ...
pf_weapons 2 ...
pf_weapons 1 ...
我希望pf_weapons中的项目总是在没有groupby的情况下分开,如下所示:
SEL_ITEM_TABLE SEL_ITEM_ID
pf_gem 2 ...
pf_gem 4 ...
pf_gem 3 ...
pf_weapons 1 ...
pf_weapons 1 ...
pf_weapons 1 ...
pf_weapons 1 ...
pf_weapons 1 ...
pf_weapons 1 ...
pf_weapons 1 ...
答案 0 :(得分:1)
你可以排除武器,然后将它们联合起来。
SELECT *, COUNT(item.sel_item_id) AS 'Count'
FROM item
where item.sel_item_table != 'pf_weapons'
GROUP BY item.sel_item_table, item.sel_item_id, item.gold
union all
SELECT *, 1
FROM item
where item.sel_item_table = 'pf_weapons'
正如@Hogan在评论中指出的那样,UNION ALL
将更具性能。