left join table built in - sql

select distinct CFR
from fleet_dwh.eu_fleet_register_v a
where event_code = 'IMP'
left join ( select distinct CFR
from fleet_dwh.eu_fleet_register_v
where event_code = 'EXP') b
on a.CFR = b.CFR
it give error ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
I expect to see the result Can't figure out where is the error
thanks

Related

SQL command not properly ended - problem with joining?

I'm trying to read data and calculate the count of LASNRO and sum of LASKMKEALV for each LYTUNNUS, but I get the error message of:
ORA-00933: SQL-komento ei päättynyt oikein 00933.
00000 - "SQL command not properly ended"
*Cause:
*Action:
Error at Line: 7 Column: 20
I'm using Oracle SQL Developer, if it matters.
SELECT
TUNNUS,
LYTUNNUS,
COUNT(LASNRO),
SUM(LASKMKEALV)
FROM
XX.XX AS T1
INNER JOIN
YY.YY AS T2 ON T1.TUNNUS = T2.ASTUNNUS
GROUP BY
LYTUNNUS
ORDER BY
COUNT(LASKMKEALV) DESC;
Oracle does not allow as for table aliases. So the FROM clause should be:
FROM XX.XX T1 JOIN
YY.YY T2
ON T1.TUNNUS = T2.ASTUNNUS
The query you seem to want is:
SELECT TUNNUS,
COUNT(LASNRO),
SUM(LASKMKEALV)
FROM XX.XX T1 INNER JOIN
YY.YY T2
ON T1.TUNNUS = T2.ASTUNNUS
GROUP BY LYTUNNUS
ORDER BY COUNT(LASKMKEALV) DESC;
WITH
with_order_col AS (
SELECT
tunnus,
lytunnus,
COUNT(lasnro) AS lasnro_count,
SUM(laskmkealv) AS laskmkealv_sum,
COUNT(laskmkealv) AS laskmkealv_count
FROM xx.xx t1
JOIN yy.yy t2 ON t1.tunnus = t2.astunnus
GROUP BY
tunnus, -- you must GROUP BY every column that is not an aggregate function
lytunnus
)
SELECT
tunnus,
lytunnus,
lasnro_count,
laskmkealv_sum
FROM with_order_col
ORDER BY
laskmkealv_count DESC
;

ORACLE sql error - ORA-00933 - executing join operation - DBeaver [duplicate]

This question already has answers here:
ORA - 00933 confusion with inner join and "as"
(2 answers)
Using Alias in query resulting in "command not properly ended"
(1 answer)
How to use the 'as' keyword to alias a table in Oracle?
(2 answers)
Closed 4 years ago.
I'm trying to execute the next:
SELECT l.id AS id
FROM s.process AS l
JOIN s.item AS r ON l.id = r.id;
But I'm getting:
Query execution failed
Reason:
SQL Error [933] [42000]: ORA-00933: SQL command not properly ended
Using:
DBeaver
ojdbc7.jar as driver
You have to remove AS when defining alias of table/view:
SELECT l.id AS id
FROM s.process l
JOIN s.item r ON l.id = r.id;
Oracle supports table aliases but It supports AS in the SELECT list but not in the FROM list:
SELECT l.id AS id
FROM s.process l
JOIN s.item r ON l.id = r.id;

External data from file throws error while using where clause

I am trying to read a text file with 2,000 values, but my where clause throws error.
SELECT mac.mac_id,mac.mac,mac.mac_type,record.soc_id
from mso_charter.mac
where record.soc_id in ('C:\Users\xyz\worldbox2_Prod_09-17-2017.txt')
join mso_charter.record on mac.record_id = record.header_id;
ERROR: syntax error at or near "join"
LINE 4: join mso_charter.record on mac.record_id = record.header_id;
^
********** Error **********
ERROR: syntax error at or near "join"
SQL state: 42601
Character: 155
This:
SELECT mac.mac_id,mac.mac,mac.mac_type,record.soc_id
from mso_charter.mac
join mso_charter.record on mac.record_id = record.header_id
where record.soc_id in ('C:\Users\xyz\worldbox2_Prod_09-17-2017.txt');
and unless you have multiple soc_Id's
where record.soc_id = ('C:\Users\xyz\worldbox2_Prod_09-17-2017.txt');
Not this:
SELECT mac.mac_id,mac.mac,mac.mac_type,record.soc_id
from mso_charter.mac
where record.soc_id in ('C:\Users\xyz\worldbox2_Prod_09-17-2017.txt')
join mso_charter.record on mac.record_id = record.header_id
Compilers are pretty picky about the order
SELECT
FROM
JOIN
WHERE
GROUP BY
HAVING
ORDER BY
Though order of execution is
FROM
JOIN
WHERE
GROUP BY
SELECT
HAVING
ORDER BY

Oracle SQL AS replacement?

Through some research I've come to realize that Oracle SQL does not support AS and thus, my statement below results in "missing keyword"
SELECT IP.Company, IP.Copay, P1.Num_Patients
FROM Insurance_Plan IP
JOIN Patient P
ON IP.Plan_Name = P.Plan_Name
JOIN
(SELECT Plan_Name, COUNT(*) AS Num_Patients
FROM Patient
GROUP BY Plan_Name) AS P1
ON P.Plan_Name = N.Plan_Name
GROUP BY IP.Company, IP.Copay, P1.Num_Patients
HAVING P1.Num_Patients =
(SELECT MAX(Num_Patients) FROM
(SELECT Plan_Name, COUNT(Patient_ID) AS Num_Patients
FROM Patient
GROUP BY Pan_Name) P2);
Where I run in to trouble is on line 8 where I have "AS P1" and I cannot for the life of me figure out what it is I need to correct to get this to run. Appreciate the help!

Oracle Query Error ORA-00933 SQL Command not properly ended

Trying to run a simple inner join in a query on a 5.1 Oracle Database.
SELECT
W.ID,
WE.CLASS
FROM
W
INNER JOIN
WE
ON (W.ID=WO.ID)
WHERE
WO.ID='688158'
It results in the Command not properly ended.
I can do
Select
W.ID, WE.CLASS from W, WE
WHERE
W.ID=WO.ID and WO.ID='688158'
and it doesn't error out but doesn't return the results I want because of the lack of join.
Thanks!
Your table name is used incorrectly. Should be:
SELECT
W.ID,
WE.CLASS
FROM
W
INNER JOIN
WE
ON (W.ID = WE.ID)
WHERE
WE.ID='688158';
WE instead of WO