mysql - How To Create Query With Conditional Group By -


i have table :

+---------+---------------+ | item_id | status        | +---------+---------------+ | 1       | active        | | 1       | sold          | | 1       | deleted       | | 2       | active        | | 2       | sold          | | 3       | active        | +---------+---------------+ 

what want simple output this. but, 1 condition. if item_id have 'deleted' status, wont show again in query. , item_id grouped single line.

+---------+---------------+ | item_id | status        | +---------+---------------+ | 2       | active        | | 3       | active        | +---------+---------------+ 

i tried using : select * table group item_id, result not expected.

it doesn't make sense have column called status, when have more 1 value. can want having:

select item_id table group item_id having sum(status = 'deleted') = 0; 

if want statuses product has, add group_concat(distinct status) statuses select


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -