gpt4 book ai didi

sql - 如何在 SQL 中引用自定义字段

转载 作者:行者123 更新时间:2023-12-03 01:04:59 27 4
gpt4 key购买 nike

我正在使用 mssql,但在使用子查询时遇到问题。真正的查询相当复杂,但其结构与此相同:

select 
customerName,
customerId,
(
select count(*)
from Purchases
where Purchases.customerId=customerData.customerId
) as numberTransactions
from customerData

我想做的是按交易数量对表进行排序,但是当我使用时

order by numberTransactions

它告诉我没有这样的字段。是否有可能做到这一点?我应该使用某种特殊关键字,例如 thisself 吗?

最佳答案

使用字段编号,在本例中:

order by 3

关于sql - 如何在 SQL 中引用自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/89820/

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