mysql - Can I combine ten similar SQL queries to one? -


this mysql query:

select round(sum(cfv.numbervalue),0) mysum jissue ji join customfieldvalue cfv on ji.id=cfv.issue ji.pkey '%pb-%'  , cfv.customfield=11381 , ji.issuestatus=10127; 

there 2 possible cfv.customfield (11381 , 11382) , 5 possible ji.issuestatus (10127 -> 10131), run query ten times changing 2 fields each time.

is possible compress 1 query return ten sums?

edit: result include empty values. currently, 8 rows returned because ji.issuestatus=10128 has no numbervalue 11381 , 11382. result include 10128 empty values 11381/2.

  1. as said wumpz , anthony grist, use group by return 2*5 sums without sums missing entries.
  2. to return sums missing entries, use left join. difference between tableexpr1 join tableexpr2 on ... , tableexpr1 left join tableexpr2 on ... left join entries tableexpr1 output when there no corresponding entries in tableexpr2.

    select ji.issuestatus, cf.id customfield_id, round(sum(cfv.numbervalue),0) mysum     jissue ji cross join customfield cf     left join customfieldvalue cfv on cfv.issue=ji.id , cfv.customfield=cf.id     ji.pkey '%pb-%'     , ji.issuestatus in (10127,10128,10129,10130,10131)     , cf.id in in (11381, 11382) group ji.issuestatus, cf.id; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -