由'order by'引起的'ora-00979'(不是按表达式分组)

时间:2012-08-20 09:11:32

标签: sql oracle

我很抱歉我的英语不好,但我会尽力描述我的问题

SELECT user_id,
       Count(user_id),
       Trunc(created_time, 'dd')
FROM   (SELECT user_id,
               created_time
        FROM   t_vote_join_user
        WHERE  created_time >= To_date('20120720', 'yyyymmdd')
               AND created_time < To_date('20120814', 'yyyymmdd')
               AND ( ( vote_id = 1270
                       AND options = '["5526"]' )
                      OR ( vote_id = 1306
                           AND options = '["5666"]' )
                      OR ( vote_id = 1320
                           AND options = '["5759"]' )
                      OR ( vote_id = 1366
                           AND options = '["5966"]' )
                      OR ( vote_id = 1393
                           AND options = '["6066"]' )
                      OR ( vote_id = 1432
                           AND options = '["6203"]' )
                      OR ( vote_id = 1452
                           AND options = '["6269"]' )
                      OR ( vote_id = 1502
                           AND options = '["6482"]' )
                      OR ( vote_id = 1610
                           AND options = '["6863"]' )
                      OR ( vote_id = 1627
                           AND options = '["6917"]' )
                      OR ( vote_id = 1651
                           AND options = '["7010"]' )
                      OR ( vote_id = 1676
                           AND options = '["7098"]' ) ))
GROUP  BY user_id,
          Trunc(created_time, 'dd')
ORDER  BY Trunc(created_time, 'dd')
  

由ora-00979引起的错误(不是按表达式分组),但是   没有'TRUNC(created_time,'dd')'

命令执行ok

3 个答案:

答案 0 :(得分:1)

通过以下方式尝试以下订单:     按3排序

答案 1 :(得分:0)

分组时,请确保选择字符串中的元素(不是组的一部分)使用适当的分组或多对一功能(例如:sum,avg等)。请发布完整的查询以获得正确的解决方案。

答案 2 :(得分:0)

尝试使用列的别名

SELECT user_id,
       Count(user_id),
       Trunc(created_time, 'dd')  AS created_date
FROM   (SELECT user_id,
 ...

GROUP  BY user_id,
          Trunc(created_time, 'dd')
ORDER  BY created_date
;