Hi Everyone
I have the code below and I am trying to find out the top 10 servers used in the last month, but having issues, not very good with SQL. Need some help or advice if possible.
I got this working on top 10 Apps but cannot figure out how to make this happen for top 10 servers.
SELECT TOP 10 dbo_LU_SERVERNAME.SERVERNAME, Count(*) AS SessionNumbers
FROM dbo_LU_SERVERNAME INNER JOIN dbo_SDB_SESSION ON dbo_LU_SERVERNAME.PK_SERVERNAMEID = dbo_SDB_SESSION.FK_SERVERNAMEID
WHERE (((dbo_SDB_SESSION.SESSIONSTART) Between Now() And DateAdd("d",-30,Now())))
GROUP BY dbo_LU_SERVERNAME.SERVERNAME
ORDER BY Count(*) DESC;
UNION ALL SELECT "Other" AS SERVERNAME, Count(*) AS SessionNumbers
FROM (dbo_LU_SERVERNAME
INNER JOIN dbo_SDB_SESSION
ON dbo_LU_SERVER.PK_SERVERID = dbo_SDB_SESSION.FK_SERVERID)
LEFT JOIN (SELECT TOP 10 dbo_LU_SERVERNAME.SERVERNAME, Count(*) AS SessionNos
FROM dbo_LU_SERVERNAME
INNER JOIN dbo_SDB_SESSION
ON dbo_LU_SERVER.PK_SERVERID = dbo_SDB_SESSION.FK_SERVERID
WHERE (((dbo_SDB_SESSION.SESSIONSTART) Between Now() And DateAdd("d",-31,Now())))
GROUP BY dbo_LU_SERVERNAME.SERVERNAME
ORDER BY Count(*) DESC) AS s ON dbo_LU_SERVERNAME.SERVERNAME = s.SERVERNAME
WHERE s.SERVERNAME Is Null
GROUP BY "Other";
This is the SQL that is working for top 10 APPS.
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
WHERE (((dbo_SDB_SESSION.SESSIONSTART) Between Now() And DateAdd("d",-30,Now())))
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
WHERE (((dbo_SDB_SESSION.SESSIONSTART) Between Now() And DateAdd("d",-31,Now())))
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";
Please note that the tables are related as: dbo_LU_SERVER ---> FK_SERVERNAMEID, PK_SERVERID dbo_LU_SERVERNAME ---> PK_SERVERNAMEID dbo.SDB.SESSION ---> FK_SERVERID
I am not sure what I am doing wrong.
Please Help.
Thank you