私は、カウントの重複なし、NUllの値と空のデータなしの結果3,5を取得しようとします。SQLプラス2列のデータ数内
select count(distinct no1), count(distinct no1) + count(distinct no2) from abc where no1
is not null
私は、カウントの重複なし、NUllの値と空のデータなしの結果3,5を取得しようとします。SQLプラス2列のデータ数内
select count(distinct no1), count(distinct no1) + count(distinct no2) from abc where no1
is not null
を試してみて、これを試してみてください。
select
count(distinct case when no1 = '' then null else no1 end),
count(distinct case when no1 = '' then null else no1 end)
+ count(distinct case when no2 = '' then null else no2 end)
from `tbl`
参照してください。Demoはこちら。
説明:count
、sum
、avg
等...これらの集約関数はその計算上のオブジェクトとしてnull
になりませんが好きです。だから空の値をnull
に変更してください。ここでcase when
を使用してください。count distinct
はあなたが望むものを得るでしょう。
それは動作します。ありがとう –
select count(distinct no1), count(distinct no1) + (select count(distinct no2) from abc where no2 is not null and no2<>'') from abc where no1 is not null
あなたがnull、空たくない場合は、この
動作していない、「キーワード 'select'の近くに不正な構文があります。」 「近くに構文が正しくない」)」 –
今質問を変更しました。 –
この作業もあります。ありがとう –
nullと空のcountを含めたくありません。結果が欲しい3 5 –