需要计数查询 [英] Count Query required
本文介绍了需要计数查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ID Time Status
----------- ----------------------- --------------------------------------------------
1 2013-12-24 00:00:00 on
2 2013-12-25 00:00:00 on
3 2013-12-26 00:00:00 on
4 2013-12-27 00:00:00 on
5 2013-12-28 00:00:00 on
6 2013-12-29 00:00:00 on
7 2013-12-30 00:00:00 on
8 2013-12-31 00:00:00 on
9 2013-12-24 00:00:00 off
10 2013-12-25 00:00:00 off
11 2013-12-27 00:00:00 off
12 2013-12-27 00:00:00 on
13 2013-12-27 00:00:00 off
14 2013-12-27 00:00:00 on
15 2013-12-27 00:00:00 off
16 2013-12-28 00:00:00 on
17 2013-12-28 00:00:00 off
18 2013-12-28 00:00:00 on
19 2013-12-29 00:00:00 off
20 2013-12-29 00:00:00 on
21 2013-12-30 00:00:00 off
22 2013-12-30 00:00:00 on
23 2013-12-30 00:00:00 off
24 2013-12-30 00:00:00 on
25 2013-12-30 00:00:00 off
26 2013-12-31 00:00:00 on
27 2013-12-31 00:00:00 off
28 2013-12-31 00:00:00 on
29 2013-12-31 00:00:00 off
30 2013-12-31 00:00:00 on
31 2013-12-31 00:00:00 off
我有这个数据,我想要一个查询,按日期和开/关分类他们
I have this Data , I want a query that categorized them by Date and by on and Off
列名称Date,On,Off,我正在使用Microsoft SQL Server 2008
with column names Date , On , Off , I am using Microsoft SQL server 2008
推荐答案
让我们说列包含日期被命名为 yourDateColumn
,列包含状态被命名为 statusColumn
,您可以执行以下操作:
Lets say the column containing date was named yourDateColumn
and the column containing status was named statusColumn
, you could do:
SELECT yourDateColumn,
SUM(statusColumn="On") as On,
SUM(statusColumn="Off") as Off
FROM yourTable
GROUP BY yourDateColumn
ORDER BY yourDateColumn
这篇关于需要计数查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文