当我运行以下查询时,它可以正常工作
select TO_CHAR(mydate ,'YYYYMMDD') , count(*) from table
where columnA = '123'
group by TO_CHAR(mydate,'YYYYMMDD')
但是当我尝试order by
失败时
select TO_CHAR(mydate ,'YYYYMMDD') , count(*) from table
where columnA = '123'
group by TO_CHAR(mydate,'YYYYMMDD')
order by mydate desc
同样当我尝试在日期做任何算术时,我得到同样的错误。
select TO_CHAR(mydate +10/24 ,'YYYYMMDD') , count(*) from table
where columnA = '123'
group by TO_CHAR(mydate,'YYYYMMDD')
order by mydate desc
有人可以建议什么是最好的订购方式并添加10小时?
答案 0 :(得分:0)
试试这个:
select TO_CHAR(mydate ,'YYYYMMDD') from table
where columnA = '123'
group by TO_CHAR(mydate,'YYYYMMDD')
order by mydate desc
即,您需要将select
的所有列都放在group by
中以使其正常工作。
修改: - 强>
select TO_CHAR(mydate ,'YYYYMMDD') , count(someID) from table
where columnA = '123'
group by TO_CHAR(mydate,'YYYYMMDD')
order by mydate desc
having count(someID)>1