我需要帮助我的查询,其中一列中的3个计数列的total为total,以下是我当前的查询:
SELECT region, COUNT(s_code), COUNT(b_code), COUNT(d_code), SUM(COUNT(s_code, b_code, d_code)) as total
FROM shilpy
GROUP BY region
ORDER BY region
我需要帮助我的查询,其中一列中的3个计数列的total为total,以下是我当前的查询:
SELECT region, COUNT(s_code), COUNT(b_code), COUNT(d_code), SUM(COUNT(s_code, b_code, d_code)) as total
FROM shilpy
GROUP BY region
ORDER BY region
2条答案
按热度按时间smdncfj31#
如果你只需要总数,你可以直接把它加起来:
y1aodyip2#
您可以使用子查询来计算特定的计数,然后获得计数的总数,而无需再次重新扫描整个表:
Demo here