[英]How to join two or more columns from one table with one column from another table, even there are NULL values in first table columns
[英]How to not display even one column is null in table
select * from WHERE col1 IS NOT NULL AND col2 IS NOT NULL AND col3 IS NOT NULL AND col4 IS NOT NULL AND col5 IS NOT NULL....AND col9 IS NOT NULL
如果您想要一種有效的方法來做到這一點,那么一種方法是持久計算列:
alter table t
add numNulls as ( (case when col1 is null then 1 else 0 end) +
(case when col2 is null then 1 else 0 end) +
(case when col3 is null then 1 else 0 end) +
. . .
) persisted;
您可以索引此列:
create index t_numNulls on t(numNulls);
然后你可以在select
中使用它:
select t.*
from t
where num_nulls = 0;
也就是說,我懷疑你真正的問題是數據 model。 我猜這 90 列實際上是一個“數組”——也就是說,都是同一個實體。 這些應該作為聯結表中的單獨行來實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.