用于检索标记/总行数的 TSQL 查询
我正在努力寻找以下问题的解决方案。 假设,有一个像这样的表,
COL1 FLAG
aaa 1
aaa 0
aaa 1
bbb 0
我需要编写一个查询来获取以下输出:
COL1_VALUE FLAGGED TOTAL
aaa 2 3
bbb 0 1
其中 FLAGGED 列包含 FLAG=1 的“aaa”行值的总数,TOTAL 列是包含以下内容的行总数: 'aaa',换句话说,查找包含 'aaa' 的行被标记的数量与包含 'aaa' 的行总数的关系。是否可以通过单个查询来实现? (即不使用临时表等)
(MSSQL2008)
I'm struggling to find a solution to the following problem.
Assume, one has a table like this
COL1 FLAG
aaa 1
aaa 0
aaa 1
bbb 0
I need to write a query to get the following output:
COL1_VALUE FLAGGED TOTAL
aaa 2 3
bbb 0 1
where FLAGGED column contains the total count of the 'aaa' row values for which FLAG=1, and TOTAL column is the total number of rows containing 'aaa', in other words find how many rows containing 'aaa' are flagged in relation to total number of rows containing 'aaa'. Is it possible with a single query? (i.e. without using temp tables etc.)
(MSSQL2008)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)