Sub query did not connected to main query

后端 未结 1 1620
名媛妹妹
名媛妹妹 2021-01-29 11:07

Below query is used to retrieve records from database to shown in report. But the SENOKO AND EUNOS column show duplicate total in every row. This seems the

1条回答
  •  庸人自扰
    2021-01-29 11:14

    Oh, your problem is simple. Your query is simply not correlated to the outer query, so you are getting the total for Senkoku (and presumably EUNO) across the entire whbal table.

    Reading your query, I figured that this was what you wanted.

    I think you need a correlation clause in the subquery, where you tie the rows in whbal to some column in one of the outer tables. Not knowing what you really want or your data structure, I can't propose a particular condition.

    EDIT:

    The correct way to connect them would be:

       (SELECT SUM(CONVERT(DECIMAL(8,3),(CONVERT(DECIMAL(8, 3), whbal.qty_good) + CONVERT(DECIMAL(8, 3), whbal.qty_slack)) * CONVERT(DECIMAL(8, 3), whbal.std_weight) / 1000)) 
        FROM whbal
        WHERE warehouse = 'SKW' and whbal.customer = customer.customer
       ) AS SENOKO
    

    0 讨论(0)
提交回复
热议问题