gpt4 book ai didi

MYSQL 如何在连接表中进行排序

转载 作者:行者123 更新时间:2023-11-29 22:03:34 24 4
gpt4 key购买 nike

我有这个 SQL 正在运行,但它没有像我想要的那样按 DESC 排序。它完全忽略了命令的顺序。

这是sql

SELECT Sales.saleId, Sales.tax, Sales.subtotal, Sales.total, Sales.created as createdTemp, Users.firstName, Users.lastName
FROM Sales
JOIN Users
ON Sales.userId = Users.userId
JOIN Companies
ON Companies.companyId = 1
ORDER BY Sales.saleId DESC

最佳答案

试试这个:

SELECT * FROM
(
SELECT Sales.saleId, Sales.tax, Sales.subtotal,
Sales.total, Sales.created as createdTemp,
Users.firstName, Users.lastName
FROM Sales
JOIN Users
ON Sales.userId = Users.userId
JOIN Companies
ON Companies.companyId = 1
) AS s
ORDER BY s.saleId DESC;

关于MYSQL 如何在连接表中进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32382636/

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