我有两个用于处理用户活动的表(serverlogdetail a,serverlogid b) 用户可以在一天内对不同的应用程序进行多次不同的登录(a.entrydate)(b.appname) 对于用户有权访问的所有应用程序,我需要返回上次登录时的列表。
SELECT b.appname ,max(to_char(a.entrydate)), a.username, a.msgnumber
FROM serverlogdetail a, serverlogid b
WHERE a.msgnumber = 1020055
AND A.entrydate BETWEEN (SYSDATE-90) AND SYSDATE
GROUP BY b.appname, a.dbname, a.username,a.msgnumber, a.entrydate
ORDER BY b.appname, max(to_char(a.entrydate))
感谢提前
答案 0 :(得分:0)
SELECT b.appname , a.username, a.msgnumber, max(to_char(a.entrydate))
FROM serverlogdetail a, serverlogid b
WHERE a.msgnumber = 1020055
AND A.entrydate BETWEEN (SYSDATE-90) AND SYSDATE
AND A.something = B.something -- the condition you're missing!!!
GROUP BY b.appname, a.username, a.msgnumber
ORDER BY b.appname, max(to_char(a.entrydate))