SQL COUNT() WHERE 多个值
我将简短地写这篇文章:我想计算我的行出现在表中的次数,其中该行是特定值,而另一行可能是 4 个不同的值。我将发布我的“猜测”,但它不起作用:
SELECT hero_selected, COUNT(hero_type) FROM heroes WHERE hero_type = 'agi' AND hero_selected = 'yt' OR hero_selected = 'yb' OR hero_selected = 'ym' OR hero_selected = 'yf
有关表的信息
表名称
英雄
行数
Hero_type
在何处选择“hero_type”
值为“agi”
仅在“hero_selected”所在的位置选择
yt、yb、ym 或 yf
如果可能的话,我也希望包含 yb 的完整代码>echo php 中的计数金额。提前非常感谢! :)
I'll make this post short: I want to count the number of times my row appears in my table where the row is a specific value And another row could be 4 different values. I'll post my "guess" which doesn't work:
SELECT hero_selected, COUNT(hero_type) FROM heroes WHERE hero_type = 'agi' AND hero_selected = 'yt' OR hero_selected = 'yb' OR hero_selected = 'ym' OR hero_selected = 'yf
INFORMATION ABOUT THE TABLE
TABLE NAME
heroes
ROW TO COUNT
hero_type
SELECT "hero_type" WHERE
Value is 'agi'
ONLY SELECT IT WHERE "hero_selected" IS
Either yt, yb, ym or yf
If possible I'd also appreciate the full code including an echo of the count amount in php. Thanks A LOT in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从我从你的问题中收集到的信息,你想要这个查询
PHP 代码可能看起来像这样,
我在这里假设你只想要一个计数,而不是像其他答案那样每个不同的
hero_selected
值一个计数表明From what I can glean from your question, you want this query
PHP code might look like this
I'm assuming here that you only want a single count, not one per different
hero_selected
value as the other answers are indicating