There is a transid field for which multiple rows will exist in this table with a list of config values. For all the transid's, I would like to retrieve all the distinct combination of transid, config_name and value fields that exist in the table group by count
I have join query which is not returning the result as expected. Below is the table structure, query used, result and expected result
Table
transid config_name value
1 payment_fee instant
2 eligible_account true
1 Block_intl_trans false
5 payment_fee provider_charge
1 eligible_account false
1 KycEligible 0
2 KycEligible 1
5 KycEligible 1
5 Block_intl_trans true
2 Block_intl_trans false
2 payment_fee provider_charge
5 eligible_account true
The above table structure implies that below are the combination of configuration values for each user.
transid KycEligible payment_fee eligible_account Block_intl_trans
1 0 instant false false
2 1 provider_charge true false
5 1 provider_charge true false
Below is the query that I used to Convert rows to columns and then group them per config_name(For every config_name, instead of multiple rows for each config key and value combination). Then select all distinct combination of KycEligible, configname and value combination that are present in the table and count of each distinct combination.
select
distinct
max(case when b.config_name = 'KycEligible' then b.config_value end) KycEligible,
max(case when b.config_name = 'payment_fee' then b.config_value end) payment_fee,
max(case when b.config_name = 'eligible_account' then b.config_value end) eligible_account,
max(case when b.config_name = 'Block_intl_trans' then b.config_value end) Block_intl_trans,
count(*) AS COUNT
from tableA b
where b.config_name in ('KycEligible', 'payment_fee', 'eligible_account', 'Block_intl_trans')
group by b.config_name
having count(*) > 1
Expected Result:
KycEligible payment_fee eligible_account Block_intl_trans Count
0 instant false false 1
1 provider_charge true false 2
My query is not returning the expected result. Can someone please help with this query?
name
column whereas these values are invalue
column. 4) Expected Result shows Count=2 in a row woth Block_intl_trans=false, but Block_intl_trans for transid=5 is true. – AkinaBlock_intl_trans
for transid=5 isfalse
ortrue
? – FaNo_FN