上一主题:Oracle - Get data from past year (Dynamic)
注意:在执行查询(从前一个线程)之后,需要连接表以显示更好的结果。
这是我的userMember
userMember表
userID memberID
0001 0001000
0003 0003000
0006 0006000
0008 0008000
0010 0010000
0013 0013000
我的MembeTable
memberID memberName
0001000 John
0003000 Doe
0006000 Rick
0008000 Jack
0010000 Cruise
0013000 Ronnie
我在加入表时遇到一些错误,因为它一直重复,我无法根据userID获取memberName(来自上一个帖子)
预期结果(我想要的结果)
userID memberName count
0001 John 3
答案 0 :(得分:0)
SELECT b.userID, m.memberName, COUNT(b.userID) AS count
FROM BookingTable b
INNER JOIN
userMember u
ON b.userID = u.userID
INNER JOIN
MembeTable m
ON u.memberID = m.memberID
WHERE b.Timebooked BETWEEN SYSDATE - INTERVAL '1' year AND SYSDATE
GROUP BY b.userID, m.memberName
HAVING COUNT(b.userID) > 2;