简体   繁体   English

sql select其中(两列之和)大于X

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

I have a dynamic SQL query based on user selections. 我有一个基于用户选择的动态SQL查询。 2 of the columns (FullBath, HalfBath) need to be counted as one for SELECT operations. SELECT操作需要将2列(FullBath,HalfBath)计为一。 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. 例如:用户搜索特定城镇中的房产,并且浴室的最小数量(HalfBath和FullBath的总和)大于或等于x。

I tried variations of: 我尝试了以下变化:

SELECT * From Rentals WHERE Town = town AND (SUM(FullBath + HalfBath) >= bathrooms ) 选择*从出租地点城镇= 城镇 AND(SUM(FullBath + HalfBath)> = 浴室

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

I found answer (don't need SUM...) 我找到了答案(不需要SUM ...)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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