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

apache - setting document root in antoher partition on ubuntu -

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

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -