gpt4 book ai didi

sql - SQL与Oracle中的分组依据不同

转载 作者:行者123 更新时间:2023-12-04 13:24:18 25 4
gpt4 key购买 nike

我有以下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

关于sql - SQL与Oracle中的分组依据不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9323973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com