如果我已经有 ORDER BY 语句和 DISTINCT,则对 mysql 中的 LEFT JOIN 记录进行分组
我有 3 个表和一个查询:
SELECT
DISTINCT assistent.id as id,
name,
events.client as client,
assistentprice.id as priceid,
value
FROM
`assistents`
LEFT JOIN `events` ON assistents.id = events.assistent
LEFT JOIN `assistentprice` ON assistents.id = assistentprice.id_assistente
ORDER BY
name
我得到的结果如下:
id | name | client | Priceid | value |
---|---|---|---|---|
88 | MARK | 44 | 12 | 7.00 |
88 | MARK | 27 | 14 | 8.00 |
88 | MARK | 44 | 15 | 11.00 |
88 | MARK | 27 | 11 | 10.00 |
88 | MARK | 44 | 10 | 9.00 |
16 | OSCAR | 49 | 21 | 8.00 |
16 | OSCAR | 14 | 23 | 9.00 |
16 | OSCAR | 14 | 22 | 7.00 |
16 | OSCAR | 49 | 19 | 9.00 |
因此,表按名称排序,但我还想查看每个助理的有序/分组客户端。 它必须是:
id | name | clientpriceid | 15 | value |
---|---|---|---|---|
88 | MARK | 27 | 12 | 7.00 |
88 | MARK | 27 | 14 | 8.00 |
88 | MARK | 44 | 例如,对于 Mark , | 11.00 |
88 | 马克 | 44 | 11 | 10.00 |
我该怎么做?
I have 3 tables, and a query:
SELECT
DISTINCT assistent.id as id,
name,
events.client as client,
assistentprice.id as priceid,
value
FROM
`assistents`
LEFT JOIN `events` ON assistents.id = events.assistent
LEFT JOIN `assistentprice` ON assistents.id = assistentprice.id_assistente
ORDER BY
name
I got a result like:
id | name | client | priceid | value |
---|---|---|---|---|
88 | MARK | 44 | 12 | 7.00 |
88 | MARK | 27 | 14 | 8.00 |
88 | MARK | 44 | 15 | 11.00 |
88 | MARK | 27 | 11 | 10.00 |
88 | MARK | 44 | 10 | 9.00 |
16 | OSCAR | 49 | 21 | 8.00 |
16 | OSCAR | 14 | 23 | 9.00 |
16 | OSCAR | 14 | 22 | 7.00 |
16 | OSCAR | 49 | 19 | 9.00 |
So, table is ordered by name, but i want to see also ordered/grouped client for every assistent. For exampe, for Mark it have to be:
id | name | client | priceid | value |
---|---|---|---|---|
88 | MARK | 27 | 12 | 7.00 |
88 | MARK | 27 | 14 | 8.00 |
88 | MARK | 44 | 15 | 11.00 |
88 | MARK | 44 | 11 | 10.00 |
How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论