Skip to Content
-2

SQL Queries Logical Operator Issue

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 25, 2017 at 10:04 PM

    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

    Add comment
    10|10000 characters needed characters exceeded