another approach with cte as( select cx_name, concat(product, ',', LEAD(product) over (partition by cx_name order by cx_name)) next_row, ROW_NUMBER() over (partition by cx_name order by cx_name) RN from purchase_wed ) select count(case when next_row = ('Table,Chair') then 1 END) purchased_both, count(case when next_row = ('Table,') or next_row = ('Table,Table') then 1 END) purchased_table, count(case when next_row = ('Chair,') or next_row = ('Chair,Chair') then 1 END) purchased_chair from cte where RN=1
@select_star_by_anant_negi2 ай бұрын
What if someone purchased chair first and then table, next_row = ('Chair','Table')
@user-gq6cg3ls7f2 ай бұрын
@@select_star_by_anant_negi what do you want to display in a column as a output?
@select_star_by_anant_negi2 ай бұрын
1. How many customers ordered both table and chair? 2. How many customers ordered only table? 3. How many customers orderedonly chair?