无法定义条件
我正在尝试定义条件 SR.PRODUCT_STOCK2 > 0
在sql代码中,因为它是sum条件的AS
,这是sql代码,
SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
,(SUM(SR.STOCK_IN)-SUM(SR.STOCK_OUT)) AS PRODUCT_STOCK2
</cfif>
FROM PRODUCT P
JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
JOIN #DSN2_ALIAS#.STOCKS_ROW SR ON P.PRODUCT_ID=SR.PRODUCT_ID
</cfif>
WHERE PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1 AND P.IS_SALES=1 AND P.IS_PURCHASE=1 AND P.IS_INTERNET=1 AND P.IS_EXTRANET=1
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
AND
(
<cfloop list="#attributes.department_id#" delimiters="," index="dept_i">
(SR.STORE = #listfirst(dept_i,'-')# AND SR.STORE_LOCATION = #listlast(dept_i,'-')#)
<cfif dept_i neq listlast(attributes.department_id,',') and listlen(attributes.department_id,',') gte 1> OR</cfif>
</cfloop>
)
<cfif isdefined('attributes.is_stock') and attributes.is_stock is 1>
AND SR.PRODUCT_STOCK2 > 0
</cfif>
</cfif>
GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
错误日志显示:无效的列名PRODUCT_STOCK2
我知道我错了定义了条件,我只是不知道如何正确定义它,需要帮助!谢谢大家的帮助!
im trying to define the condition SR.PRODUCT_STOCK2 > 0
inside the sql code, since it AS
of sum condition, here is the sql code
SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
,(SUM(SR.STOCK_IN)-SUM(SR.STOCK_OUT)) AS PRODUCT_STOCK2
</cfif>
FROM PRODUCT P
JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
JOIN #DSN2_ALIAS#.STOCKS_ROW SR ON P.PRODUCT_ID=SR.PRODUCT_ID
</cfif>
WHERE PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1 AND P.IS_SALES=1 AND P.IS_PURCHASE=1 AND P.IS_INTERNET=1 AND P.IS_EXTRANET=1
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
AND
(
<cfloop list="#attributes.department_id#" delimiters="," index="dept_i">
(SR.STORE = #listfirst(dept_i,'-')# AND SR.STORE_LOCATION = #listlast(dept_i,'-')#)
<cfif dept_i neq listlast(attributes.department_id,',') and listlen(attributes.department_id,',') gte 1> OR</cfif>
</cfloop>
)
<cfif isdefined('attributes.is_stock') and attributes.is_stock is 1>
AND SR.PRODUCT_STOCK2 > 0
</cfif>
</cfif>
GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
the error log says: Invalid column name PRODUCT_STOCK2
i know that i wrongly defined the condition, i just don't know how to define it right, need help! Thanks everyone for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你将不得不使用像这样的having子句:
You are going to have to use a having clause like so: