pat*_*m83 6 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_date like '11%'
and shipper_id = XXXXXX
group by origin,destination,ship_date,trip_number, ship_number
Run Code Online (Sandbox Code Playgroud)
当我在Oracle中运行此SQL时,它给出了ORA-00936:缺少表达式.如果我删除distinct关键字,它运行正常.谁能告诉我这两件事之间的区别?
nar*_*yan 15
不同的关键字适用于所有选定的列,因此您必须在选择之前放置它
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
Run Code Online (Sandbox Code Playgroud)