[英]SQL distinct with group by in Oracle
我有以下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_date like '11%'
and shipper_id = XXXXXX
group by origin,destination,ship_date,trip_number, ship_number
当我在Oracle中运行此SQL时,它给出了ORA-00936:缺少表达式。 如果我删除distinct关键字,它运行正常。 谁能告诉我这两件事之间的区别?
不同的关键字适用于所有选定的列,因此您必须在选择之前放置它
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.