没有数据时获得零计数 [英] Get zero count when no data exists

查看:82
本文介绍了没有数据时获得零计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一张表来维护所有严重性细节。以下是我的查询,

< pre lang =" text">

选择计数(严重性)作为计数,严重程度,日期与严重程度的日期& lt ; getdate() - 严重程度为25组

< / pre>

当我执行此查询时,我会得到结果,

< pre lang =" text">

计算严重性日期

------ -------- ------

1高03-06-1991

< / pre>

我的表中有很多严重程度,如高,中,低,严重,最小等。所以我希望查询结果是这样的。

< pre lang =" text">

计算严重性日期

- ---- -------- ------

1高03-06-1991

0中等03-06-1991

0低03-06-1991

0关键03-06-1991

< / pre>



请帮忙。在此先感谢。

Hi,

I have a table to maintain all the severity details. Below is my query,
<pre lang="text">
select count(severity) as Count, severity,date from severities where date &lt; getdate() - 25 group by severity
</pre>
When I execute this query, I will get the result as,
<pre lang="text">
Count Severity Date
------ -------- ------
1 High 03-06-1991
</pre>
I have many severities in my table such as High, Medium, Low, Critical, Minimal, and so on. So I want the query result something like this.
<pre lang="text">
Count Severity Date
------ -------- ------
1 High 03-06-1991
0 Medium 03-06-1991
0 Low 03-06-1991
0 Critical 03-06-1991
</pre>

Please help. Thanks in advance.

推荐答案

首先你的qyery是错误的....



First of all your qyery is wrong....

Msg 8120, Level 16, State 1, Line 1 Column 'date ' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.







请查看以下查询......这可能是h elps you ...






Please look at the below query...this might helps you...

select count(severity), severity,date from severities where date < getdate() - 25 group by severity,date


这篇关于没有数据时获得零计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆