MySQL:计算两个字段
我有一张看起来像这样的表:
Pizza ----|| Topping
====================
Cheese--|| Olives
====================
Ham----- || Tuna
====================
Cheese-- || Olives
====================
Cheese-- || Tuna
====================
我想获得每种类型的披萨的数量,所以在上面的表格中会有一个火腿披萨和2个奶酪披萨(因为奶酪+橄榄是重复的,应该只计算在内)一次)。基本上,我需要计算每两个相等元素的每一行并按披萨分组。
该查询的结果应该是:
Pizza ----|| Count
====================
Cheese--|| 2
====================
Ham----- || 1
====================
谢谢!
I have a table that looks like this:
Pizza ----|| Topping
====================
Cheese--|| Olives
====================
Ham----- || Tuna
====================
Cheese-- || Olives
====================
Cheese-- || Tuna
====================
I would like to obtain the number of pizzas of each type, so in the table above there would be one ham pizza, and 2 cheese pizzas (since cheese+olives is repeated and should be counted only once). Basically, I need to count each row for each two equal elements and group by pizza.
The result from that query should be:
Pizza ----|| Count
====================
Cheese--|| 2
====================
Ham----- || 1
====================
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this