在mySQL中显示数据时计算行数

时间:2010-01-27 20:18:53

标签: sql mysql

我有两个问题

select TC,li,it as ee from results 
where li = "not_applicable" and cpirt = "uu_X1"

以上查询将输出10个结果, 但如果我把计数放在同一个查询中,那么只有一个结果。

select TC,li,it,COUNT(TC) as ee from results 
where li = "not_applicable" and cpirt = "uu_X1"

如何使用MYSQL

使第二个查询输出每个TC的计数

感谢。

1 个答案:

答案 0 :(得分:3)

添加GROUP BY TC

我愿意:

select TC,COUNT(TC) as ee from results 
where results.li = "not_applicable" and results.cpirt = "uu_X1"
GROUP BY TC