我面临一个棘手的问题,因为我的表有两个不同的列,用于决定记录是活动还是不活动。 (两个不同的列,因为同一个DB的变化一次又一次不是我的当然。)
数据库中的字段为bit
类型。任何人都可以建议一个从表中获取记录的查询。
离。 select * from product(isActive = 0或isCancelled = 1)
答案 0 :(得分:1)
无活性:
select * from product where isActive = 0 or isCancelled =1
活性
select * from product where isActive = 1 and isCancelled =0
答案 1 :(得分:1)
我认为这是编写此查询的好方法
select * from product where isActive = 1 and isCancelled = 0 -- Active records
select * from product where not (isActive = 1 and isCancelled = 0) -- Inactive records
答案 2 :(得分:0)
我会选择计算出的值:
select *, (isActive = 1 and isCancelled = 0) as active
from product
或者更好的是创建一个隐藏这种丑陋的视图:
create view complete_product as
select *, (isActive = 1 and isCancelled = 0) as active
from product