从 Visual FoxPro 中的表连接选择中选择



我想获取用户的信息及其上次登录日期。

select * from Users as UU
inner join
(select user_id, max(d_login) from Logins group by user_id) as LL
on UU.user_id = LL.user_id

加入在 VFP 中不起作用。我们无法在此处连接表进行查询?

VFP 需要在连接中使用 ALLTRIM((,否则比较 2 个值可能会导致不需要的数据。 你的代码应该是这样的

select * from Users as UU
inner join
(select user_id, max(d_login) from Logins group by 
user_id) as LL
on ALLT(UU.user_id) == ALLT(LL.user_id)

假设您已将User_ID规范化为两个表中的主键,即用户和登录名,并且具有相同的字段类型和字段长度。我创建了表用户和登录名,并使用示例数据测试了此查询,它运行顺利并给出了确切的结果。

select 
Users.User_id, 
Users.Cell1, 
Users.Name, 
max(d_login) 
from Logins, users 
WHERE users.user_id = logins.user_id 
GROUP BY 
Users.user_id, Users.Cell1, Users.Name, Logins   

最新更新