I use SqlPlus.
There is a lot of solutions and examples out there for related problems, but I haven't been able to fix my issue.
Expected result: 1 line that gives information about a library member that borrowed a book for the longest time. (displaying the amount of time: ex. Johnson John has ...: 31 days)
My current query:
SELECT DISTINCT m.firstname || ' ' || m.lastname || ' has borrowed for the longest time: ' || ROUND(MAX(l.date_of_return - l.date_borrowed)) || ' days' "Longest time borrowed"
FROM loans l
JOIN members m
ON l.memberid = m.memberid
WHERE l.date_of_return - l.date_borrowed = (SELECT MAX(date_of_return - date_borrowed) FROM loans)
/
Tables used:
LOANS:
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
ISBN NOT NULL VARCHAR2(20)
SERIAL_NO NOT NULL NUMBER(2)
DATE_BORROWED NOT NULL DATE
DATE_OF_RETURN DATE
MEMBERID NOT NULL VARCHAR2(11)
EXTEND VARCHAR2(5)
MEMBERS:
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
MEMBERID NOT NULL VARCHAR2(11)
LASTNAME NOT NULL VARCHAR2(20)
FIRSTNAME VARCHAR2(20)
Error:
ERROR at line 1: ORA-00937: not a single-group group function
I think I'm overlooking a simple solution. Thanks in advance.