Filter information from a CASE WHEN SQL and only results that contain all information

Asked

Viewed 179 times

-1

I need to return only the result that contains all the information that in the case of this image and the ID='8187'

Select d.ID, d.post_title, d.post_type,
MIN(CASE WHEN b.name = 'Resinas' THEN b.name END) AS categoria, 
MIN(CASE WHEN b.name = 'featured' THEN b.name END) AS destaque
from wp_term_taxonomy a
inner join wp_terms b on a.term_id = b.term_id
inner join wp_term_relationships c on a.term_taxonomy_id = c.term_taxonomy_id
inner join wp_posts d on c.object_id = d.id
where b.name IN ('Resinas', 'featured') and d.post_type = 'product'
GROUP BY d.ID

inserir a descrição da imagem aqui

  • group by d.id HAVING ( MIN( ...) IS NOT NULL AND MIN(....) IS NOT NULL ) would help if sql were text ...

1 answer

0


Be able to solve as follows

Select *
FROM
(
Select d.ID, d.post_title, d.post_type,
MIN(CASE WHEN b.name = 'Resinas' THEN b.name END) AS categoria, 
MIN(CASE WHEN b.name = 'featured' THEN b.name END) AS destaque
from wp_term_taxonomy a
inner join wp_terms b on a.term_id = b.term_id
inner join wp_term_relationships c on a.term_taxonomy_id = c.term_taxonomy_id
inner join wp_posts d on c.object_id = d.id
where b.name IN ('Resinas', 'featured') and d.post_type = 'product'
GROUP BY d.ID
) AS x
WHERE x.destaque = 'featured' AND x.post_type = 'product' AND x.categoria = 'Resinas'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.