简体   繁体   English

甲骨文集团

[英]Oracle group by

I am very new to Oracle (a few hours). 我是Oracle的新手(几个小时)。 My experience is all with MySQL. 我的经验全是MySQL。

My query is very basic in my mind, but the group by just doesn't seem to be returning the expected results. 我的查询在我看来是非常基本的,但是group by似乎并没有返回预期的结果。 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. 我得到的结果将有多个行,这些行具有相同的start_time,display_name和1计数。查询中返回了400多个行,并且所有计数均为1。

EDIT: Below are the results. 编辑:下面是结果。 So I now understand why the group by is not working properly. 因此,我现在了解了为什么group by无法正常工作。 In MySQL I would use date(start_time) to correct this. 在MySQL中,我将使用date(start_time)来更正此问题。 Is there something similar for Oracle? 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 : 您需要将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.

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