【发布时间】:2015-01-16 13:56:18
【问题描述】:
假设我有下表:
CREATE TABLE person
(
key integer NOT NULL AI ,
name varchar NOT NULL DEFAULT 0,
column1 integer NOT NULL DEFAULT 0,
column2 integer NOT NULL DEFAULT 0,
column3 integer NOT NULL DEFAULT 0,
column4 integer NOT NULL DEFAULT 0,
column5 integer NOT NULL DEFAULT 0,
column6 integer NOT NULL DEFAULT 0,
CONSTRAINT pk PRIMARY KEY (key)
)
现在我想要一个 sql,它可以让我得到至少有两列值非零的行,对于列 column1 到 column6。
例如如果我们有行
1 TEST 0 0 6 1 0 5
2 ABCD 0 0 0 0 0 5
3 DEFG 0 0 4 1 0 5
4 HIJK 0 0 0 1 0 0
所以我的查询应该返回 ID 1 和 3,因为它们至少有 2 个非零列。
【问题讨论】: