TransWikia.com

How do i write a sql query that is contingent on 2 columns in one conditional?

Stack Overflow Asked by ja08prat on December 16, 2021

Take the following psuedo query on a table called userscore:

select average of userscore.points
where (userid = userid)
and ((userscore.year != given year) && (userscore.week != given week))

How do i write a query that will filter out a specific week/year column combination? For example this week is the 29th week of 2020. How do i write a query that will filter out only the 29th week of 2020 and not the 29th weeks of 2019/2018/2017 etc?

One Answer

How do i write a query that will filter out only the 29th week of 2020 and not the 29th weeks of 2019/2018/2017 etc?

This is more of a question about boolean logic than SQL.

Assuming that given_year and given_week are the parameters to your query, you want something like:

where not (year = given_year and week = given_week)

You can also express this with or:

where year <> given_year or week <> given_week

Answered by GMB on December 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP