sql语句查询多个字段不等于零怎么写?
问题描述:
例如:要查询房租、电费、水费这三个字段,只要有一个不为0的情况下的ID,怎么写
答
select ID from table where 房租 <> 0 or 电费 <> 0 or 水费 <> 0;
答
select id from table where (房租 + 水费 + 电费) > 0
答
select ID from table where 房租 <>'' or 电费 <>'' or 水费 <>''
答
用 or (或),and(且)来写
三个之中 : df 电费 fz 房租 sf 水费
两个为 0 另一个 不为 0,(可设置为大于 0)
select * from table _ name where fz = 0 and sf = 0 and df > 0 or fz = 0 and df = 0 and sf > 0 or df = 0 and sf = 0 and fz > 0
答
select ID from table where 房租!=0 && 水费!=0 && 电费!=0
答
select id from <表> where 房租!=0 or 电费!=0 or 水费!=0