create table ithelp170811 (
id int not null
, c1 char(1)
, c2 int
, c3 int
, c4 int
, c5 char(1)
);
insert into ithelp170811 values
(1, 'a', null, null, null, null),
(2, null, null, null, null, null),
(3, null, 4, null, null, null),
(4, null, null, 5, null, null),
(5, 'b', 2, 3, 4, null),
(6, null, null, null, 7, null),
(7, null, null, null, null, 'c');
-- use the ANSI coalesce function for same type columns
select *
from ithelp170811
where coalesce(c1, c5) is not null
or coalesce(c2, c3, c4) is not null;
id | c1 | c2 | c3 | c4 | c5
----+--------+--------+--------+--------+--------
1 | a | [null] | [null] | [null] | [null]
3 | [null] | 4 | [null] | [null] | [null]
4 | [null] | [null] | 5 | [null] | [null]
5 | b | 2 | 3 | 4 | [null]
6 | [null] | [null] | [null] | 7 | [null]
7 | [null] | [null] | [null] | [null] | c
(6 筆資料列)