简体   繁体   中英

sql select where (sum of 2 columns) is greater than X

I have a dynamic SQL query based on user selections. 2 of the columns (FullBath, HalfBath) need to be counted as one for SELECT operations. EX: a user searches for a property in a specific town and minimum number of bathrooms (HalfBath and FullBath combined) is greater than or equal to x.

I tried variations of:

SELECT * From Rentals WHERE Town = town AND (SUM(FullBath + HalfBath) >= bathrooms )

=========================

I found answer (don't need SUM...)

SELECT *
FROM Rentals
WHERE Town = Town
AND FullBath + HalfBath >= Bathrooms

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