简体   繁体   中英

Oracle group by

I am very new to Oracle (a few hours). My experience is all with MySQL.

My query is very basic in my mind, but the group by just doesn't seem to be returning the expected results. After a few hours of searching I am hoping someone here can help!

Here is the my code:

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';

The results I get will have multuple rows with the same start_time, display_name and a count of 1.. Over 400 rows return in the query and all have a count of 1.

EDIT: Below are the results. So I now understand why the group by is not working properly. In MySQL I would use date(start_time) to correct this. Is there something similar for 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

Thanks in advance!

You need to apply your trunc(start_time) to the group by, as in :

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM