I have been told to create a query that will show the top 10 most used applications in our company, and on the 11th row should group all other rows into it and call the record "Other" and sum all the sessions together.
How do I modify this code to only show monthly records?
Code Snippet
SELECT TOP 10 dbo_LU_APPNAME.APPNAME, Count(*) AS SessionNos
FROM dbo_LU_APPNAME INNER JOIN dbo_SDB_SESSION ON dbo_LU_APPNAME.PK_APPNAMEID =
dbo_SDB_SESSION.FK_APPNAMEID
GROUP BY dbo_LU_APPNAME.APPNAME
ORDER BY Count(*) DESC;
UNION ALL SELECT "Other" AS APPNAME, Count(*) AS SessionNos
FROM (dbo_LU_APPNAME
INNER JOIN dbo_SDB_SESSION
ON dbo_LU_APPNAME.PK_APPNAMEID = dbo_SDB_SESSION.FK_APPNAMEID)
LEFT JOIN (SELECT TOP 10 dbo_LU_APPNAME.APPNAME, Count(*) AS SessionNos
FROM dbo_LU_APPNAME
INNER JOIN dbo_SDB_SESSION
ON dbo_LU_APPNAME.PK_APPNAMEID = dbo_SDB_SESSION.FK_APPNAMEID
GROUP BY dbo_LU_APPNAME.APPNAME
ORDER BY Count(*) DESC) AS s ON dbo_LU_APPNAME.APPNAME = s.APPNAME
WHERE s.APPNAME Is Null
GROUP BY "Other";
The dbo_SDB_SESSION
table has many fields and from those we will need to use:
- SESSIONSTART
- SESSIONEND
The code could be something like this:
WHERE (((dbo_SDB_SESSION.SESSIONSTART) Between Now() And DateAdd("d",-30,Now())))
Question
How do I modify the above code to only show the previous month's data?
This is an SQL View into Access 2007.