sql - how can i get ot_total and ot_shipping into one row in mysql? -


how can ot_total , ot_shipping 1 row in mysql ?

i want charge of each orders ot table. how can table bellow in mysql ?
thank much.

set foreign_key_checks=0;  -- ---------------------------- -- table structure `ot` -- ---------------------------- drop table if exists `ot`; create table `ot` (   `id` int(10) not null auto_increment,   `orders_id` int(10) default null,   `class` varchar(30) default null,   `value` float(30,0) default null,   primary key  (`id`) ) engine=myisam auto_increment=6 default charset=utf8;  -- ---------------------------- -- records of ot -- ---------------------------- insert `ot` values ('1', '1', 'ot_shipping', '10'); insert `ot` values ('2', '1', 'ot_total', '100'); insert `ot` values ('3', '1', 'ot_insurance', '1'); insert `ot` values ('4', '2', 'ot_shipping', '10'); insert `ot` values ('5', '2', 'ot_total', '80'); 

enter image description here

enter image description here

select orders_id,         sum(case when class='ot_shipping' value else 0 end) shipping,        sum(case when class='ot_total' value else 0 end) total ot group orders_id; 

sqlfiddle


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -