Jump to content

CONDITIONAL statement using OR and AND


jmichael68

Recommended Posts

I have a problem when trying to query the table closed_mbl.  I want to return the COUNT of all records that contain the locations below while excluding all these records that contain anything else besides AIR.  How would I do this?  Right now it returns the count of everything from all these locations.  The field "method" is ignored.

 

SELECT COUNT(*) FROM closed_mbl WHERE location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT' OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON' OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC' AND method = 'AIR'

Link to comment
Share on other sites

Use parentheses:

 

SELECT COUNT(*) FROM closed_mbl
WHERE (location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT'
OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON'
OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC')
AND method = 'AIR'

 

Or use IN:

 

SELECT COUNT(*) FROM closed_mbl
WHERE location IN
('ALL','AUCKLAND','BRAZIL','DALIAN','EXPORT','GALWAY','ISUNICOV','KOLIN','SGALWAY','SHANNON','SOMI','SUZHOU','UNICOV','WUJIANG','WUJIANGCC')
AND method = 'AIR'

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.