I am learning mysql and trying to do some exercises.
In a library data base, I am supposed to find the number of loans that goes overdue.
I tried this solution(https://www.codeproject.com/Questions/754851/How-do-I-combine-multiple-calculations-in-MySQL-un)
Here is my script(https://pastebin.com/LPFnwBVt)
create table loanlist
(
LoanID int not null,
Cop_Av int not null, -- value 1-10
LoanDt datetime not null,
Cop_OnLoan int not null, -- VALUE 1 or 2
MemID int not null, -- VALUE BTWN 1-1200
DueDt datetime not null,
ReturnDt datetime not null
)
;
SELECT concat((OverDue/Total)*100) AS Percentage_OverDue
FROM (SELECT COUNT(*) AS Total
FROM loanlist
INNER JOIN (
SELECT COUNT(*) AS OverDue
FROM loanlist
WHERE ReturnDt > DueDt) )
;
I have the aliases, but why is it still showing (Error Code: 1248. Every derived table must have its own alias)?
What I have tried:
SELECT concat((OverDue/Total)*100) AS Percentage_OverDue
FROM (SELECT COUNT(*) AS Total
FROM loanlist
INNER JOIN ( SELECT COUNT(*) AS OverDue
FROM loanlist
WHERE ReturnDt > DueDt) as a) as b;