sql - Querying with where, having and order by together in mysql -
i have following table...
id awaiting approve decline 100 1 0 0 100 1 0 0 102 1 0 0 103 0 1 0 104 0 1 0 104 1 0 0 106 1 0 0 107 0 1 0 107 1 0 0 107 1 0 0
i have following code,...
select count(*) total ( select id table1 group id having count(*) = 2 , max(awaiting = 1) > 0 ) q
what above code count id repeated twice , @ least 1 of id awaititng=1,
but want is, want show above results repeated id listed if awaiting 1. (like id 100).
from above query, result 2 (2) id's 100 , 104, because group id.
now, how show result id's has awaiting=1, if id same (in case must have 3 list of rows)?
help please....
this should work:
select * table1 id in (select id table1 group id having count(*) = 2 , max(awaiting) = 1) , awaiting = 1
the results are:
╔═════╦══════════╦═════════╦═════════╗ ║ id ║ awaiting ║ approve ║ decline ║ ╠═════╬══════════╬═════════╬═════════╣ ║ 100 ║ 1 ║ 0 ║ 0 ║ ║ 100 ║ 1 ║ 0 ║ 0 ║ ║ 104 ║ 1 ║ 0 ║ 0 ║ ╚═════╩══════════╩═════════╩═════════╝
ande here is sqlfiddle demo.
Comments
Post a Comment