我已經圍着周圍看到很多關於分組的話題。我需要在週六結束的兩週之前進行分組。 http://sqlfiddle.com/#!6/e2fea/1/0星期六結束時間爲2週期間組
CREATE TABLE contacts (
Total Numeric(9,2)
created DATE
);
INSERT INTO contacts (Total,created) VALUES('100','2009-01-01');
INSERT INTO contacts (Total,created) VALUES('50','2009-01-02');
INSERT INTO contacts (Total,created) VALUES('100','2009-01-03');
INSERT INTO contacts (Total,created) VALUES('50','2009-01-04');
INSERT INTO contacts (Total,created) VALUES('75','2009-01-05');
INSERT INTO contacts (Total,created) VALUES('150','2009-01-06');
INSERT INTO contacts (Total,created) VALUES('170','2009-01-07');
INSERT INTO contacts (Total,created) VALUES('111','2009-01-08');
INSERT INTO contacts (Total,created) VALUES('125','2009-01-09');
INSERT INTO contacts (Total,created) VALUES('151','2009-01-10');
INSERT INTO contacts (Total,created) VALUES('128','2009-01-11');
INSERT INTO contacts (Total,created) VALUES('175','2009-01-12');
INSERT INTO contacts (Total,created) VALUES('100','2009-01-13');
INSERT INTO contacts (Total,created) VALUES('50','2009-01-14');
INSERT INTO contacts (Total,created) VALUES('75','2009-01-15');
INSERT INTO contacts (Total,created) VALUES('150','2009-01-16');
INSERT INTO contacts (Total,created) VALUES('170','2009-01-17');
INSERT INTO contacts (Total,created) VALUES('111','2009-01-18');
INSERT INTO contacts (Total,created) VALUES('125','2009-01-19');
INSERT INTO contacts (Total,created) VALUES('151','2009-01-20');
INSERT INTO contacts (Total,created) VALUES('128','2009-01-21');
INSERT INTO contacts (Total,created) VALUES('175','2009-01-22');
INSERT INTO contacts (Total,created) VALUES('100','2009-01-23');
INSERT INTO contacts (Total,created) VALUES('50','2009-01-24');
INSERT INTO contacts (Total,created) VALUES('75','2009-01-25');
INSERT INTO contacts (Total,created) VALUES('150','2009-01-26');
INSERT INTO contacts (Total,created) VALUES('170','2009-01-27');
INSERT INTO contacts (Total,created) VALUES('111','2009-01-28');
INSERT INTO contacts (Total,created) VALUES('125','2009-01-29');
INSERT INTO contacts (Total,created) VALUES('151','2009-01-30');
INSERT INTO contacts (Total,created) VALUES('128','2009-01-31');
INSERT INTO contacts (Total,created) VALUES('111','2009-02-01');
INSERT INTO contacts (Total,created) VALUES('125','2009-02-02');
INSERT INTO contacts (Total,created) VALUES('151','2009-02-03');
INSERT INTO contacts (Total,created) VALUES('128','2009-02-04');
我知道01/03/2009是週六,我想從啓動。我想總計總數,然後在前2周顯示結束日期的分組,如果週六結束還沒有結束,則顯示總計到當前日期。
Total Date
250 1/3/2009
1680 1/17/2009
1750 1/31/2009
515 2/4/2009
這只是一個月,輸出實際上會持續到當前日期。
這些是你的類型嗎? varchar和日期? – 2015-02-06 17:34:52
不,我很抱歉,錯過了當我創建SQL小提琴表...它實際上是數字(9,2)和日期是日期。 – Viperwolfmn 2015-02-06 17:39:05
和你的SQL版本在小提琴上是否正確? – 2015-02-06 17:42:12