我有以下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关键字,它运行正常。谁能告诉我这两件事之间的区别呢?
答案 0 :(得分:14)
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