我正在编写一个 sql 脚本,并且在 select 子句中有 2 条语句,格式如下:
max(case when ... then ... end)
我想在这些 case 语句之后添加其他语句,但我收到一条错误消息:
Error at line 1
not a GROUP BY expression
这是我的脚本:
create table mydb.test1 as
select distinct substr(testdb.wtags.FAO, 1) as Account_Number,
max(Case
when testdb.wtags.descriptor like 'Company for%' then ('CM' || substr(testdb.wtags.DESCRIPTOR, 18)) end ) Division,
max(Case
when testdb.wtags.value like 'CC%' then substr(testdb.wtags.value, 1) end) Department,
-------------------------------
'CM' || substr(testdb.wtags.DESCRIPTOR, 18, 22) as Division,
substr(testdb.wtags.value, 1, 10) as Department,
substr(testdb.MASTERFILE.Workday_Description, 1, 20) as Description,
' ' Responsible_Person,
' ' Address,
' ' Delete_Flag,
' ' Freeze_Flag
-----------------------
from testdb.wtags
join testdb.masterfile
on testdb.wtags.fao = testdb.MASTERFILE.workday_number
--where testdb.wtags.descriptor like 'Company for%'
--OR testdb.wtags.value like 'CC%'
--order by Account_Number Desc
group by testdb.wtags.fao;
我想在两条虚线之间添加语句,但这会导致错误。如果我删除这些语句,一切正常。我正在使用 Toad for Oracle。