SQL differs from group in Oracle

I have the following 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 

When I run this SQL in Oracle, it gives ORA-00936: missing expression. If I delete a single keyword, it will work fine. Can someone tell me the difference between these two things?

+4
source share
1 answer

The Distinct keyword for all selected columns, so you need to put it before you 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 
+13
source

Source: https://habr.com/ru/post/1396974/


All Articles