我有一个数组$array=array(B,c)
和一个这样的表:
id coulmn1
1 A
2 B
3 C
4 C
5 F
我需要将这些分组为我的给定值,如下所示:
groupby_Column count
group_variable 3
A 1
F 1
我需要使用group by子句输出上述结果。
答案 0 :(得分:0)
仍然不完全清楚你想要什么,但我有一个去:
你在php数组中有值。您希望在column1上进行分组,但是您希望将数组中的值视为一个组。
在上述情况下,您可以创建类似于下面的查询:
select case when column1 in('b','c') then 'group_variable' else column1 end as 'group',
count(id)
from table
group by case when column1 in('b','c') then 'group_variable' else column1 end
您可以使用implode()函数从数组生成in子句。