Oracle中SQL与group by不同
我有以下SQL:Oracle中SQL与group by不同,sql,oracle,group-by,distinct,Sql,Oracle,Group By,Distinct,我有以下SQL: select origin,destination,to_char(to_date(substr(ship_date,1,6),'YYMMDD'), 'YYYY-MM-DD'),ship_date,trip_number, distinct ship_number from shipment a where a.scc_code in ('xxxxx','xxxxx','xxxxx') and load_status = 'S' and ship_d
select
origin,destination,to_char(to_date(substr(ship_date,1,6),'YYMMDD'),
'YYYY-MM-DD'),ship_date,trip_number, distinct ship_number
from shipment a
where
a.scc_code in ('xxxxx','xxxxx','xxxxx')
and load_status = 'S' and ship_date like '11%'
and shipper_id = XXXXXX
group by origin,destination,ship_date,trip_number, ship_number
当我在Oracle中运行此SQL时,它给出了ORA-00936:缺少表达式。如果我删除distinct关键字,它运行正常。有人能告诉我这两件事的区别吗?Distinct关键字适用于所有选定的列,因此您必须将其放在select之前
select distinct
origin,destination,to_char(to_date(substr(ship_date,1,6),'YYMMDD'),
'YYYY-MM-DD'),ship_date,trip_number, ship_number
from shipment a
where
a.scc_code in ('xxxxx','xxxxx','xxxxx')
and load_status = 'S' and ship_date like '11%'
and shipper_id = XXXXXX
group by origin,destination,ship_date,trip_number, ship_number
你想干什么?您已按所有这些列进行分组,包括ship_编号,因此,它已经是不同的。不同的关键字应该应用于所有选定的列..谢谢我意识到我出错的地方。是的。我意识到我犯的错误。当向所有选定的列添加不同的关键字时,它是有效的。谢谢。如果这是对您的问题的正确答案,那么将其标记为正确答案将是礼貌的。