在一个查询中来自同一表的多个COUNT SELECTS [英] Multiple COUNT SELECTS from the same table in one query
本文介绍了在一个查询中来自同一表的多个COUNT SELECTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于某些人来说,它看起来很简单,但我只是无法理解.
我一次又一次地从同一个表中有多个MS-SQL SELECT查询:
For some people it might look very simple, but I just simply can't get it.
I have multiple MS-SQL SELECT queries from the same table over and over:
SELECT count(Page) as tAEC
FROM someTable
WHERE Page LIKE '%AEC%'
下一个
SELECT count(Page) as tTOL
FROM someTable
WHERE Page LIKE '%TOL%'
以此类推...
and so on...
什么是写此查询的更有效方法.我用Google搜索了一堆类似的问题,但是我无法解决其中的任何问题.因此,非常感谢您的帮助.
What would be more efficient way to write this query. I Googled bunch of similar questions but I couldnt make any of them to work. So any help is greatly appreciated.
推荐答案
SELECT sum(case when Page LIKE '%AEC%' then 1 end) as tAEC,
sum(case when Page LIKE '%TOL%' then 1 end) as tTOL
FROM someTable
这篇关于在一个查询中来自同一表的多个COUNT SELECTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文