gpt4 book ai didi

mysql - LIMIT 显示不同的表字段

转载 作者:行者123 更新时间:2023-11-29 00:23:13 24 4
gpt4 key购买 nike

下面是我的表格:

1. tbluser
UserNumber - PK
Name
MemberType - Number
StationNumber - FK (connected to StationNo of tblStation)

2.tblStation
StationNo - PK
StationName

3.tblUserLogs
LogID - PK
UserID - FK (connected from UserNumber of tblusers)
LastLog

我只想显示 Name (tblusers)、StationName(tblStation) 和 LastLog(tblUserLogs),其中 MemberType 不等于 1。

这是我的尝试...

SELECT tblusers.FirstName, tblstation.StationName, tblUserLogs.LastLog
FROM (tblstation INNER JOIN tblusers ON tblstation.StationNo = tblusers.StationNumber)
INNER JOIN tblUserLogs ON tblusers.UserNumber = tblUserLogs.UserID
WHERE (((tblusers.MemberType)<>1))

但是,我得到了用户的重复记录。它显示所有 LastLog 数据,而不是显示最新的。

我应该怎么做?

最佳答案

使用这个查询:

SELECT tblusers.FirstName, tblstation.StationName, MAX(tblUserLogs.LastLog)
FROM (tblusers LEFT JOIN tblstation ON tblstation.StationNo = tblusers.StationNumber)
LEFT JOIN tblUserLogs ON tblusers.UserNumber = tblUserLogs.UserID
WHERE tblusers.MemberType != 1

关于mysql - LIMIT 显示不同的表字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20281085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com