Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
MySQL
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:

MySQL
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;
Posted
Updated 27-Jun-22 18:24pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900