2017-12-09 10 views
0

以下のクエリは、量> 0だった行のUNIQUE_MEM_IDを数えるのに最適です。このクエリーのロジックを変更して、1か月にsum(amount)> 100 の異なるUNIQUE_MEM_IDを取得したいと考えています。select、groupby by subquery

概念的には、任意の行のamount> 100、1か月の任意のユーザーのsum(amount)> 100までのロジックの変更からです。

select to_char(optimized_transaction_date, 'YYYY-MM') as month, cobrand_id as cobrand, 
    count(distinct UNIQUE_MEM_ID) as distinct_count 
into temp_09.z_members 
from yi_fourmpanel.card_panel 
and amount >0 
group by to_char(optimized_transaction_date, 'YYYY-MM'), cobrand; 

答えて

0

having句を使用します

select to_char(optimized_transaction_date, 'YYYY-MM') as month, 
     cobrand_id as cobrand, 
     count(distinct UNIQUE_MEM_ID) as distinct_count 
into temp_09.z_members 
from yi_fourmpanel.card_panel 
group by to_char(optimized_transaction_date, 'YYYY-MM'), cobrand 
having sum(amount) > 100; 
+0

を、私はこのクエリを実行し、「持つ総和(量)> 100」は、クエリではなかったかのように同じ値が返されました。確かに、私はロジックを "sum(amount)> 10000"に変更しましたが、違いはありますが違いはありません。まあまあですが、私はUNIQUE_MEM_IDごとに "100(sum)(amount)> 100"を探しています。それぞれのcobrandではありません。私はあなたのクエリは後者のためだと思う – ZJAY

+0

任意の考えですか?ありがとうございました – ZJAY