我正在尝试查找在 2012 年 5 月 1 日至 2012 年 5 月 30 日之间开放的开放票。
所以,我应该得到:5 月 1 日:0,5 月 2 日 0,3 日:2
但我目前得到的是 5 月 1 日:2、2 日:2、3 日:2,然后每 3 天开始上涨
数据 :
CREATE TABLE bugs
(
BUG_ID NUMBER PRIMARY KEY,
REPORTED_DATE DATE NOT NULL,
DESCRIPTION VARCHAR2(20),
PRIORITY NUMBER(2),
ASSIGNED_TO VARCHAR2(10),
CLOSED_DATE DATE,
NOTE VARCHAR2(20)
);
INSERT INTO BUGS VALUES (1230, '25-APR-12', NULL, 3, 'Team 3', '28-APR-12', NULL);
INSERT INTO BUGS VALUES (1231, '29-APR-12', NULL, 1, 'Team 1', '29-APR-12', NULL);
INSERT INTO BUGS VALUES (1232, '03-MAY-12', NULL, 1, 'Team 1', '03-MAY-12', NULL);
INSERT INTO BUGS VALUES (1233, '03-MAY-12', NULL, 1, 'Team 3', '08-MAY-12', NULL);
INSERT INTO BUGS VALUES (1234, '04-MAY-12', NULL, 2, 'Team 5', '15-MAY-12', NULL);
INSERT INTO BUGS VALUES (1235, '04-MAY-12', NULL, 2, 'Team 1', NULL, NULL);
INSERT INTO BUGS VALUES (1236, '05-MAY-12', NULL, 1, 'Team 2', '06-MAY-12', NULL);
INSERT INTO BUGS VALUES (1237, '05-MAY-12', NULL, 3, 'Team 3', '10-MAY-12', NULL);
INSERT INTO BUGS VALUES (1238, '09-MAY-12', NULL, 4, 'Team 5', '16-MAY-12', NULL);
INSERT INTO BUGS VALUES (1239, '09-MAY-12', NULL, 5, 'Team 6', NULL, NULL);
INSERT INTO BUGS VALUES (1240, '12-MAY-12', NULL, 5, 'Team 2', '30-MAY-12', NULL);
INSERT INTO BUGS VALUES (1241, '12-MAY-12', NULL, 1, 'Team 1', '12-MAY-12', NULL);
INSERT INTO BUGS VALUES (1242, '13-MAY-12', NULL, 4, 'Team 4', '20-MAY-12', NULL);
INSERT INTO BUGS VALUES (1243, '15-MAY-12', NULL, 4, 'Team 3', '01-AUG-12', NULL);
INSERT INTO BUGS VALUES (1244, '15-MAY-12', NULL, 2, 'Team 4', '20-MAY-12', NULL);
INSERT INTO BUGS VALUES (1245, '20-MAY-12', NULL, 2, 'Team 4', NULL, NULL);
INSERT INTO BUGS VALUES (1246, '22-MAY-12', NULL, 2, 'Team 4', '23-MAY-12', NULL);
INSERT INTO BUGS VALUES (1247, '25-MAY-12', NULL, 2, 'Team 1', '29-MAY-12', NULL);
INSERT INTO BUGS VALUES (1248, '30-MAY-12', NULL, 1, 'Team 1', '01-JUN-12', NULL);
INSERT INTO BUGS VALUES (1249, '05-JUN-12', NULL, 1, 'Team 2', '07-JUN-12', NULL);
COMMIT;
到目前为止我的代码:
DECLARE
v_date bugs.closed_date%type := '01-may-12';
v_end_date bugs.closed_date%type := '20-may-12';
v_openbugs NUMBER(10);
BEGIN
WHILE v_date <= v_end_date
LOOP
SELECT COUNT(bug_id)
INTO v_openbugs
FROM bugs
WHERE bugs.reported_date < v_date
AND v_date > bugs.closed_date;
DBMS_OUTPUT.PUT_LINE (v_date ||' '|| v_openbugs);
v_date := v_date + 1;
END LOOP;
END;
我需要在 PL/SQL 中执行此操作。