Skip to Content
-2

SQL Queries Logical Operator Issue

Oct 25, 2017 at 06:57 PM

23

avatar image

I have tow queries. Query 1 does not give right result where 2 gives right result.. It is the way I am applying filter on Hub field. Can someone please explain what is wrong with hub filter in Query 2.

First value of hub (GRECAR) belongs to Division value LA and second value of Hub ( VE) belongs to Division Value LV

--Wrong Query

SELECT "CalMonth", SUM("WorkingCapitalPercentSales") AS "WorkingCapitalPercentSales_SUM" FROM "_SYS_BIC"."com.colpal.xc.brof.Backend.Finance/CV_WCPercentSales" WHERE ("Division" = 'LA' or "Division" = 'LV') AND ( "Hub" <> 'GRECAR' or "Hub" <> 'VE') AND "CalYear" = '2018'

GROUP BY "CalMonth" ORDER BY "CalMonth" ASC

--Correct Query SELECT "CalMonth", SUM("WorkingCapitalPercentSales") AS "WorkingCapitalPercentSales_SUM" FROM "_SYS_BIC"."com.colpal.xc.brof.Backend.Finance/CV_WCPercentSales" WHERE ("Division" = 'LA' or "Division" = 'LV') AND ( "Hub" <> 'GRECAR') AND ("Hub" <> 'VE') AND "CalYear" = '2018'

GROUP BY "CalMonth" ORDER BY "CalMonth" ASC

SQL
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sergio Guerrero Oct 25, 2017 at 10:04 PM
0

I am not sure what you consider wrong vs right, however, I believe you need to group your Division and Hub query based on the where condition parts.

are you trying to display data within those divisions but not within the Hubs?

or within the divisions and only specific hubs per division -- that is how your desired output may need to be approached

Share
10 |10000 characters needed characters left characters exceeded