Suppose we have summary table called summary
with the following fields: date
, user_id
, song_id
and count
. It shows at the end of each day how many times in her history a user has listened to a given song.
A second table called daily
records whether a user listens to a particular song. This table is used to update the first table. If a song is in the daily
table but not in the summary
table, then a new record is created in the summary
table with the appropriate counts.
Question/Problem I am looking through some sample solutions and was not sure about the particular notation in this answer:
SELECT A.USERID, A.SONG, SUM(A.COUNT) COUNT
FROM
(SELECT USERID, SONG, COUNT FROM SUMMARY
UNION ALL
SELECT USERID, SONG, COUNT FROM DAILY WHERE DATE = NOW()) A
GROUP BY A.USERID, A.SONG
Why is there a COUNT
beside A.COUNT
in the following line: SUM(A.COUNT) COUNT
? Likewise, where is there an A
after DATE = NOW())
in the following line: WHERE DATE = NOW()) A
?