我有两个表,如下所示。SQL:计数(*)和groupby与不同的表
第一表tblCategory
第二表tblWord
Required Output
在输出时,
TotalCount
是count(*)
与group by categoryid
从tblWord
Played
是count(*)
与where isPlayed = 1 group by categoryid
从tblword
所以从2表中获取的结果,我想下面的查询这是不对的。
select (select count(*) from tblwords group by categoryid) as count, (select count(*) from tblwords where isPlayed = 1 group by categoryid) as played, categoryID, categoryname from tblcategory
查询中的任何建议以获取必需的输出或任何有用的链接?
@m哈桑我们可以通过上面的查询只得到isPlayed = 1点的记录? – Giri
添加WHERE条件...检查编辑 –
@mhasan:isPlayed是bool ...但我真的很惊讶我们可以应用sum()。有确切的输出。并学到新的东西“总和”:) – Devang