简体   繁体   中英

filter multiple rows in sql

I have table like

Company   Year
--------------
AxisBank  2018  
AxisBank  2019  
AxisBank  2020  
ICICIBank 2018  
ICICIBank 2019  
ICICIBank 2020  

Now I want to filter only Axis Bank and year less than 2020. So that output should be like below

Company   Year
--------------
AxisBank  2020  
ICICIBank 2018  
ICICIBank 2019  
ICICIBank 2020  

Can someone please help me with Query

You can use:

where company <> 'AxisBank' or year = 2020

You can also express this as:

where not (company = 'AxisBank' and year < 2020)

You can use full Query like below:

SELECT * FROM tableName 
WHERE Company != 'AxisBank' OR (Company = 'AxisBank' AND Year >= 2020)

So it will filter out, Company AxisBank and Year is less than 2020.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM