Pergunta de entrevista da empresa Amazon

write a code in R/SQL: Given a table with three column, (id, category, value) and each id has 3 or less category (price, size, color). Now, how can I find those id's for which the value of two or more category matches to one another? For eg: ID1 (price 10, size M, color Red), ID2 (price 10, Size L, Color Red) , ID3 (price 15, size L, color Red) Then the output should be two rows: ID1 ID2 and ID2 ID3

Respostas da entrevista

Sigiloso

8 de out. de 2019

select category, category_value, count(1) as matching_categories, group_concat(id) from b_product group by category, category_value having matching_categories>=2

2

Sigiloso

3 de out. de 2018

SELECT f_id, l_id ,COUNT(l_id) FROM( SELECT a1.id as f_id, a2.id As l_id from table a1 JOIN table a2 ON a1.id 1;

2