我有一個表:爲了唯一帳戶按日期
create table remote (account int ,datecreated datetime,status int)
insert into remote (account , datecreated,status)
values
(123,'2015-08-25',1),
(123,'2015-08-25',1),
(123,'2015-09-26',1),
(1238,'2015-08-25',1),
(123,'2014-08-25',1),
(123,'2014-08-26',1),
(1238,'2014-08-25',1),
(1238,'2014-08-25',1),
(1235,'2014-08-25',1),
(1234,'2014-09-22',1),
(1234,'2014-09-22',1),
(1234,'2014-10-29',1),
(1236,'2014-10-25',1);
在這裏,我想獲得的唯一的帳戶數每個月/年,其中狀態= 1 例如使用上面的數據:
輸出將
count | month
-------------
1 |9/2015
2 |8/2015
2 |10/2014
1 |9/2014
3 |8/2014
我怎樣才能使這項工作?
我使用SQL 2012
從上面的數據應該只有1 9/2014 ,因爲它有相同的帳號,http://sqlfiddle.com/#!6/3f5db/1 – jfishbow
@jfishbow更新檢查現在http://sqlfiddle.com /#!6/3f5db/2 –