I am having trouble resolving this issue. I am doing some audit exercises for the university and would like to understand this before the exam in 2 days.
Ive tried something (which is Ill post at the end). Please, kindly, this is my first database object, so my attempts may seem very silly to you.
The question is: Which artist / has the most hits at the moment? Show the first and last artist name / s and their address. The ORDER BY clause cannot be used. Write one SQL expression. Use subqueries.
Relevant tables in the database:
Shows (ShowName, ArtistId, ShowStartDate, ShowEndDate) Artists (ArtistId, FirstName, FamilyName, Address, PhoneNum)
We assume that ArtistId, ShowStartDate, FirstName, FamilyName, and Address cannot be empty.
Now, I think that I have to count the number of impressions that every artist has at the moment. Then get ArtistId for the artist / s that has / has the most. Use ArtistId to get information about the artist (names and address).
I got to this (which is very wrong):
SELECT FirstName, FamilyName, Address FROM Artists WHERE ArtistId = (SELECT ArtistId FROM Shows WHERE ArtistId = (SELECT MAX(Counted) FROM (SELECT ArtistId, COUNT(ArtistId) AS Counted FROM Shows WHERE ShowEndDate IS null GROUP BY ArtistId) GROUP BY ArtistId));
Well I do not know
SELECT ArtistId, COUNT(ArtistId) FROM Shows WHERE ShowEndDate IS null GROUP BY ArtistId
gives me a table counting how many times the ArtistId list is displayed. And this is good. But from this table of results I need to get ArtistId / s of those with the highest score.
And here I am lost.
Can anyone shed some light?
(As for which DBMS I use: we must use one created and provided by the university. Its the simplest SQL. Easier than Access 2010).
thanks
(If you give an answer [thanks, thank you], could you also briefly explain the reasons for this?)