ORA-00937——Oracle中GROUP BY搭配CASE WHEN的一則SQL報錯
寫了一個SQL,語句是這樣的
select to_char('countdate', 'YYYY-MM-DD') "日期",
count(case
when activetime > 60 * 60 then
count(1)
end) ">=1h",
count(case
when activetime > 120 * 60 then
count(1)
end) ">=2h",
count(case
when activetime > 180 * 60 then
count(1)
end) ">=3h",
count(case
when activetime > 240 * 60 then
count(1)
end) ">=4h",
count(case
when activetime > 300 * 60 then
count(1)
end) ">=5h",
count(case
when activetime > 360 * 60 then
count(1)
end) ">=6h"
from ELMP_ANALYSIS_LOGINTIMEDETAIL
where activetime > 60 * 60
and countdate between to_date('&1', 'YYYY-MM-DD') and
to_date('&2', 'YYYY-MM-DD')
group by to_char('countdate', 'YYYY-MM-DD')
order by 1;
執行的時候,一直報錯ORA-00937,仔細檢查,發現在count裡面還套了一層count,導致報錯,修改後的語句如下:
select countdate "日期" count(case
when activetime > 60 * 60 then
activetime
end) ">=1h",
count(case
when activetime > 120 * 60 then
activetime
end) ">=2h",
count(case
when activetime > 180 * 60 then
activetime
end) ">=3h",
count(case
when activetime > 240 * 60 then
activetime
end) ">=4h",
count(case
when activetime > 300 * 60 then
activetime
end) ">=5h",
count(case
when activetime > 360 * 60 then
activetime
end) ">=6h"
from ELMP_ANALYSIS_LOGINTIMEDETAIL
where activetime > 60 * 60
and countdate between to_date('&1', 'YYYY-MM-DD') and
to_date('&2', 'YYYY-MM-DD')
group by countdate
order by 1;來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-1783791/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql case when, Exist ,group by ,聚合SQL
- SQL中的CASE WHEN使用SQL
- Oracle case when改寫SQLOracleSQL
- sql中case when的小學SQL
- SQL Case WhenSQL
- Oracle 條件索引 case when 報錯解決方案Oracle索引
- 案例:oracle中case when的用法Oracle
- SQL中的case when then else end用法SQL
- ORACLE CASE WHEN 及 SELECT CASE WHEN的用法Oracle
- Oracle group by與case when統一單位後統計數量Oracle
- Oracle Case WhenOracle
- Oracle的order by case whenOracle
- SQL Case when 的使用方法SQL
- ORACLE SQL開發where子句之case-whenOracleSQL
- PL/SQL Case when應用SQL
- SQL Server CASE WHEN ... THEN ... ELSE ... ENDSQLServer
- mysql中case when的使用MySql
- mysql中的case when 與if()MySql
- sql server select case when的用法SQLServer
- SQL中的case when then else end用法 【詳細】轉載SQL
- oracle plsql case when_end case小記OracleSQL
- SQLServer使用case when中的order bySQLServer
- ORACLE多欄位CASE WHENOracle
- Laravel 中 sql 查詢 使用 group by 報錯問題。LaravelSQL
- oracle面試題[關於case when的用法]Oracle面試題
- ORA-00937: not a single-group group functionFunction
- mysql case when then 使用MySql
- SQL語句case when外用sum與count的區別SQL
- Oracle vs PostgreSQL Develop(30) - Index&Case whenOracleSQLdevIndex
- ORA-00937: not a single-group group function的解決方法Function
- Case when 支援變數變數
- case when遇上null值Null
- 轉 sql 中 case 的用法SQL
- 【專案實戰】---SQLServer中case when的簡單用法SQLServer
- SQL中Group By的使用SQL
- sqlserver與oracle case when else ,isnull語法差別SQLServerOracleNull
- Oracle 中 case的用法Oracle
- SQL Server、Oracle中CASE 與COUNT合用計數SQLServerOracle