每组多桌最大n
我知道有很多同样的问题,但我很难让它在多个表连接上工作。我有 3 个表
userinfo
user_id | firstname | lastname
subnumbers
subnumber | fkuserid
transaction
transid | fksubnumber | expires | transdate
这是我正在工作的部分
SELECT *
FROM (SELECT *
FROM subtransactions
WHERE Expires < now()
ORDER BY NewSubTrans DESC) AS s
GROUP BY FKSubNum
我想做的是选择订阅已过期的所有用户。为了确定用户是否过期,我从交易表中提取最后一笔交易及其子编号,fk 字段是到其他表的链接。
i know there is heaps of this same question but im having trouble making it work on multiple table joins. i have 3 tables
userinfo
user_id | firstname | lastname
subnumbers
subnumber | fkuserid
transaction
transid | fksubnumber | expires | transdate
heres the part i have working
SELECT *
FROM (SELECT *
FROM subtransactions
WHERE Expires < now()
ORDER BY NewSubTrans DESC) AS s
GROUP BY FKSubNum
What i am trying to do is select all users with a subscription that is expired. to determine if a user is expired i pull the last transaction from the transaction table with thier sub number, the fk fields are the links to the other tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从你的描述来看,我认为你根本不需要任何团体。尝试仅使用这两个连接:
编辑如果它按照下面的注释中的建议返回多行,请在选择列表中使用
DISTINCT
:From your description, I don't think you need any group at all. Try it with just these two joins:
EDIT If it returns multiple rows as suggested in comments below, use
DISTINCT
in the select list:这将获取所有 user_ids
来获取完整的用户数据
This will get all user_ids
To get full user data