sql - 使用 SQL Server 的列名无效
问题描述
我想减去 to 的值POSquantity
,iPay88quantity
但出现错误
列名无效
我的代码:
select distinct
tblCurrTrxIPAY88.strAmount as IPay88,
tblCurrTrxIPAY88.strPOSOnlineRefNo,
count(tblCurrTrxIPAY88.strPOSOnlineRefNo) as iPay88quantity,
b.strCostCentreID,
b.strPOSOnlineRefNo,
count(b.strPOSOnlineRefNo) as POSquantity,
strPayTypeCode, b.strRemarks as Agency,
tblMachine.strDesc As KioskName,
SUM(b.dblPaidAmt) as POS24,
SUM(b.dblPaidAmt) - tblCurrTrxIPAY88.strAmount as RMVarince,
POSquantity - iPay88quantity as Varince
from
tblCurrTrxMaster as b
inner join
tblMachine on b.strMachID = tblMachine.strMachID
inner join
tblCurrTrxIPAY88 on b.strPOSOnlineRefNo = tblCurrTrxIPAY88.strPOSOnlineRefNo
where
strPaymentMethod = '02'
and b.dtmCreated >= '1/23/2020'
and b.strTransStatus = '01'
group by
b.strCostCentreID , b.strPOSOnlineRefNo, b.strPayTypeCode, b.strRemarks,
tblMachine.strDesc, tblCurrTrxIPAY88.strAmount,
tblCurrTrxIPAY88.strPOSOnlineRefNo
解决方案
iPay88Quantity 不是表中的列名,它是一个计算字段 - 您需要对基础字段进行数学运算,而不是计算字段,即:
POSquantity - count(tblCurrTrxIPAY88.strPOSOnlineRefNo) as Variance
推荐阅读
- json - 如何命名我的反应组件以容纳嵌套 JSON 中的元素?
- json - 使用 shell 脚本进行 Ip:port 连接测试
- r - 在R中使用grepl省略字符串中的数字
- sql - 如何获取 SQL 中每个唯一相邻值中的值?
- r - 对 data.table 进行 BY 操作而不进行聚合
- python - 我想在视图模板中对一个对象调用两次 get_queryset。我该怎么做?
- javascript - 检查日期的更好方法是在今天日期之前/之后 1 到 2 天使用时刻
- json - Google 表格 JSON 提要 - 我想要数据而不是架构
- javascript - 在 JavaScript 中实现递归回溯?
- json - 使用 jq 将带有换行符的文本文件转换为 json