sql - joining 3 field in mysql -


i have sql query using uin

    select sum(scores_ofexpert.score) scores_ofexpert     scores_ofexpert.user_id = '30' , scores_ofexpert.score > '0'     union     select sum(scores_ofexpert.score) scores_ofexpert     scores_ofexpert.user_id = '30' , scores_ofexpert.score < '0'     union     select sum(scores_ofexpert.score) scores_ofexpert     scores_ofexpert.user_id = '30' 

this extract sum of negative scores,sum of positive scoes , sum of scores of user; this

 -------------  |-10        |  -------------  |30         |  -------------  |20         |  ------------- 

but want result this

 -------------------------------------  |n_sum      |p_sum      |sum        |  -------------------------------------      |-10        |30         |20         |  ------------------------------------- 

how it?

you can use case

 select  sum(case when s.score < 0 s.score else 0 end) n_sum,  sum(case when s.score > 0 s.score else 0 end) p_sum,  sum(s.score) `sum`  scores_ofexpert s    s.user_id = '30'  

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -