mysql - Query in a SQL table -
i have following tables:
http://sqlfiddle.com/#!2/1e991/1
but have problem! output of query is:
date slot sum(successful) successful percentage ota_name users_si july, 02 2013 00:00:00+0000 2 120 120 41.6667 campana 2 50 july, 02 2013 00:00:00+0000 1 200 200 25 campana 2 50 july, 02 2013 00:00:00+0000 1 150 150 53.3333 campana 3 80 july, 01 2013 00:00:00+0000 2 100 100 20 campana 1 20 july, 01 2013 00:00:00+0000 3 440 440 4.5455 campana 1 20 july, 01 2013 00:00:00+0000 1 700 700 2.8571 campana 1 20
and need sum of successful same date , campaign, example, have in july 1 campaign 1 3 rows, need sum successful of 3 rows, , campaign 2 two rows, need sum successful of 2 rows, , campaign 3 1 rows, need sum successful of 1 row same. , percentage division between sum(successful) , users_si
the output need is:
date slot sum(successful) successful percentage ota_name users_si july, 02 2013 00:00:00+0000 2 320 120 41.6667 campana 2 50 july, 02 2013 00:00:00+0000 1 320 200 25 campana 2 50 july, 02 2013 00:00:00+0000 1 150 150 53.3333 campana 3 80 july, 01 2013 00:00:00+0000 2 1240 100 20 campana 1 20 july, 01 2013 00:00:00+0000 3 1240 440 4.5455 campana 1 20 july, 01 2013 00:00:00+0000 1 1240 700 2.8571 campana 1 20 can me?
sqlfiddle here
select other.date date, other.slot, other.successful, calc.sum_successful, max((case when (rule.tree_si = dms.tree) dms.numberresponses end))/successful percentage, other.name ota_name, other.successful successful, max((case when (rule.tree_si = dms.tree) dms.numberresponses end)) users_si aca_ota_other other join aca_dms_rules rule on other.name = rule.ota_name join aca_dms dms on dms.date = other.date , rule.tree_si = dms.tree join (select name, sum(successful) sum_successful aca_ota_other group name) calc on other.name = calc.name group other.date, other.name, other.successful order other.date desc
Comments
Post a Comment