2010-12-07 52 views
0

我有使用查詢 SELECT TRUNC的記錄(createdon, 'HH')CREATEDON,COUNT(*)FROM WHERE LABSTATUS = 1 AND CREATEDON> = TO_DATE('01/07/2010 10 ','DD/MM/YYYY hh') GROUP BY trunc(createdon,'hh') 以小時爲單位。我需要將計數值放置在網格中的相應時間列中。 我該怎麼辦?任何想法使用VB6和Oracle

+0

能否請您將標題更改爲更具體的一個。這個問題與vb6無關。 – HamoriZ 2010-12-07 08:46:00

回答

0

你可以這樣說:

時間都在列

SELECT TRUNC(createdon,'hh'), SUM(CASE WHEN hh=1 THEN 1 ELSE 0) h1, 
           SUM(CASE WHEN hh=2 THEN 1 ELSE 0) h2 ..... 
FROM TABLle1, 
(SELECT 1 AS hh FROM dual 
UNION 
SELECT 2 AS hh FROM dual 
UNION 
SELECT 3 AS hh FROM dual 
.... 
) hours 
WHERE LABSTATUS=1 AND CREATEDON >=TO_DATE('01/07/2010 10','DD/MM/YYYY hh') AND 
TRUNC(createdon,'hh')= hours.hh 
GROUP BY TRUNC(createdon,'hh') 

營業時間爲行:

SELECT hours.hh, SUM(CASE WHEN TRUNC(createdon,'hh')= hours.hh THEN 1 ELSE 0 END) hh,         
    FROM TABLle1, 
    (SELECT 1 AS hh FROM dual 
    UNION 
    SELECT 2 AS hh FROM dual 
    UNION 
    SELECT 3 AS hh FROM dual 
    .... 
    ) hours 
    WHERE LABSTATUS=1 AND CREATEDON >=TO_DATE('01/07/2010 10','DD/MM/YYYY hh')  
    GROUP BY hours.hh 

這個查詢將導致這樣

  • row 1 12

    行2 0

    排3 4

...

+0

謝謝..但我得到了計數值和相應的時間..但我需要將該計數值放在網格中..例如:01:59 PM 2 ..在網格列標題中有1:00-2:00Pm計數值2必須放在 – Arthi 2010-12-07 08:47:09