Home:ALL Converter>View with Group By Causes Invalid Identifier on AVG Alias

View with Group By Causes Invalid Identifier on AVG Alias

Ask Time:2018-11-06T06:46:46         Author:Michael Cook

Json Formatter

Oracle says I have an invalid identifier, I have looked at other solutions saying to encapsulate in a subquery but I cannot get that to work so far. I am thinking possibly the join may have something to do with it.

I am trying to create a view showing vendor names, and for each vendor, the average amount of time between when an invoice was created and paid for (each vendor has multiple invoices), but only if that average is greater than or equal to 1.5. I am then to sort the list in descending order by this average.

CREATE OR REPLACE VIEW Vend_Date_Avgs AS
SELECT V.Vendor_Name, AVG(I.Invoice_Due_Date - I.Invoice_Date) AS Avg_Between
FROM Vendors V, Invoices I
WHERE V.Vendor_ID = I.Vendor_ID
GROUP BY V.Vendor_Name
HAVING Avg_Between >= 1.5
ORDER BY Avg_Between DESC;

Any and all help is appreciated!

Author:Michael Cook,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53163381/view-with-group-by-causes-invalid-identifier-on-avg-alias
yy