无法定义条件

发布于 2024-12-12 00:12:29 字数 1824 浏览 0 评论 0原文

我正在尝试定义条件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放肆 2024-12-19 00:12:29

你将不得不使用像这样的having子句:

HAVING (SUM(SR.STOCK_IN)-SUM(SR.STOCK_OUT)) > 0

You are going to have to use a having clause like so:

HAVING (SUM(SR.STOCK_IN)-SUM(SR.STOCK_OUT)) > 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文