[英]Oracle group by
我是Oracle的新手(幾個小時)。 我的經驗全是MySQL。
我的查詢在我看來是非常基本的,但是group by似乎並沒有返回預期的結果。 經過幾個小時的搜索,我希望這里的人能為您提供幫助!
這是我的代碼:
SELECT trunc(start_time), display_name, count(*)
FROM TblName
WHERE (DISPLAY_NAME like '%Advise the customer how they can change their marketing preferences%')
OR (DISPLAY_NAME like '%Inform customer on relevant ads%')
OR (DISPLAY_NAME like '%Is the customer requesting to block%')
GROUP BY start_time, display_name
HAVING start_time >= '2013-10-24';
我得到的結果將有多個行,這些行具有相同的start_time,display_name和1計數。查詢中返回了400多個行,並且所有計數均為1。
編輯:下面是結果。 因此,我現在了解了為什么group by無法正常工作。 在MySQL中,我將使用date(start_time)來更正此問題。 Oracle有類似的東西嗎?
11-SEP-13 02.16.42.809000000 PM Advise the customer how they can change their marketing preferences. 1
25-SEP-13 11.56.05.814000000 AM Advise the customer how they can change their marketing preferences. 1
26-SEP-13 11.17.29.737000000 AM Advise the customer how they can change their marketing preferences. 1
24-OCT-13 10.53.17.941000000 AM Advise the customer how they can change their marketing preferences. 1
26-OCT-13 10.24.25.099000000 AM Is the customer requesting to block? 1
23-OCT-13 08.28.58.234000000 PM Advise the customer how they can change their marketing preferences. 1
25-OCT-13 02.50.49.329000000 PM Inform customer on relevant ads 1
26-OCT-13 11.46.45.686000000 AM Advise the customer how they can change their marketing preferences. 1
28-OCT-13 10.12.31.613000000 AM Inform customer on relevant ads 1
25-OCT-13 11.38.24.570000000 AM Inform customer on relevant ads 1
提前致謝!
您需要將trunc(start_time)應用於組,例如:
SELECT trunc(start_time), display_name, count(*)
FROM TblName
WHERE (DISPLAY_NAME like '%Advise the customer how they can change their marketing preferences%')
OR (DISPLAY_NAME like '%Inform customer on relevant ads%')
OR (DISPLAY_NAME like '%Is the customer requesting to block%')
GROUP BY trunc(start_time), display_name
HAVING trunc(start_time) >= '2013-10-24';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.