【发布时间】:2019-07-27 02:41:33
【问题描述】:
我是 MySQL 新手(使用 SQLite)并且正在处理更复杂的查询
假设我的数据库类似于
tablename = "stages"
id | results | stage | parent_id
1 | no | 'stage1' | 1
2 | no | 'stage1' | 1
3 | yes | 'stage1' | 2
4 | no | 'stage2' | 2
我正在尝试做的查询是添加一个COUNT 列,计算results where stage = stage1 的数量
期望的结果是:
parent_id | stage | stage_no_count | stage_yes_count
我该怎么做呢?
编辑: 对于所有的答案,谢谢!我只是想了解这样一个简单查询的逻辑。我可以将它重新应用于更复杂的查询,但很好奇我将如何做一个简单的例子。
【问题讨论】:
-
哪个 MySQL 版本?
SELECT VERSION()另请参阅 Why should I provide an MCVE for what seems to me to be a very simple SQL query? 以提供示例数据和预期结果。
标签: mysql