Question: I would like to make a select statement using CASE statement and INNER JOIN. But I don't know what is wrong that is giving me

I would like to make a select statement using CASE statement and INNER JOIN. But I don't know what is wrong that is giving me error: "ORA-00918: column ambiguously defined 00918. 00000 - "column ambiguously defined"

This is what I have so far: SELECT custname, CASE WHEN COUNT(custname) = 1 THEN 'One-time buyer' WHEN COUNT(custname) = 2 THEN 'Two-time buyer' ELSE 'Frequent buyer' END AS "Customer Classification" FROM si.saleinv INNER JOIN si.car ON saleinv.custname = car.custname GROUP BY custname HAVING LOWER (carmake) = 'mercedes';

When I try without the inner join it works... but then I can't select only the buyers of mercedes carmake.

SELECT custname, CASE WHEN COUNT(custname) = 1 THEN 'One-time buyer' WHEN COUNT(custname) = 2 THEN 'Two-time buyer' ELSE 'Frequent buyer' END AS "Customer Classification" FROM si.saleinv GROUP BY custname ;

How can I fix it? (Oracle database)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!