Here is my task:
List the full name of members, their DETAIL_DAILYLATEFEE and the average of DETAIL_DAILYLATEFEE for all members whose DETAIL_DAILYLATEFEE is less than the average of all DETAIL_DAILYLATEFEE.
Your query MUST contain a subquery. Do not use GROUP BY in your query.
Your result should be as shown below. Note that each member is only listed once.
Here is what I have so far:
SELECT DISTINCT(CONCAT(MEM_FNAME, " ", MEM_LNAME)) AS "Full Name",
detailrental.DETAIL_DAILYLATEFEE,
AVG(DETAIL_DAILYLATEFEE) AS "Average late fee" FROM membership
JOIN rental ON membership.MEM_NUM = rental.MEM_NUM
JOIN detailrental ON rental.RENT_NUM = detailrental.RENT_NUM
WHERE detailrental.DETAIL_DAILYLATEFEE <
(SELECT AVG(DETAIL_DAILYLATEFEE) FROM detailrental);
I need to have the AVG(DETAIL_DAILYLATEFEE) column show up. But I'm getting the following error:
[ERROR 1140 (42000) at line 1: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'mimir.membership.MEM_FNAME'; this is incompatible with sql_mode=only_full_group_by
query returned no results!][1]
[1]: https://i.stack.imgur.com/uIpzL.png # This account is new so I can't post pictures yet
I suspect I'm supposed to use CASE but I'm pretty new to it so I'm not sure how I'd go about doing that.