限制 - mysql 查询
我想知道如何通过 id_offers 数量而不是行数来限制输出。例如
SELECT A.id_offer, T.tags
FROM offer A
INNER JOIN offer_has_tags Z
ON A.id_offer = Z.offer_id_offer
INNER JOIN tags T
ON Z.tags_id_tags = T.id_tags
WHERE state = 0
ORDER BY date
DESC LIMIT 0, 10
输出:
id_offer tags
77 xx
76 xx
76 xx
75 xx
75 xx
74 xx
74 xx
73 xx
73 xx
72 xx
编辑:在这种情况下,仅应算作 6 个报价。
I would like to know how can i limit the output by the number of id_offers and not the number of rows. For example
SELECT A.id_offer, T.tags
FROM offer A
INNER JOIN offer_has_tags Z
ON A.id_offer = Z.offer_id_offer
INNER JOIN tags T
ON Z.tags_id_tags = T.id_tags
WHERE state = 0
ORDER BY date
DESC LIMIT 0, 10
output:
id_offer tags
77 xx
76 xx
76 xx
75 xx
75 xx
74 xx
74 xx
73 xx
73 xx
72 xx
Edit: In this case only should be count as 6 offers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否正是您想要的,但我认为是:
或更简单:
I'm not sure if this is exactly what you want, but I think it is:
or the more simple:
你可以试试这个:
you can try this:
您只需使用 DISTINCT:
SELECT DISTINCT A.id_offer, T.tags
来自报价 A
内连接offer_has_tags Z
ON A.id_offer = Z.offer_id_offer
You simply have to use DISTINCT:
SELECT DISTINCT A.id_offer, T.tags
FROM offer A
INNER JOIN offer_has_tags Z
ON A.id_offer = Z.offer_id_offer