mysql - how to insert values to a table with another table data using case statatement -


enter image description here have table "test_comparitive_analysis" column fields gender, , value. table "cmparitive_analysis_dup" column fields "boys" , "girls". problem want insert column values of "test_comparitive_analysis" "cmparitive_analysis_dup". condition if gender "f" "value" column data move "girls"column anf if "m" "value" column data move "boys"

how can possible

enter image description here

  "create table if not exists `comparitive_analysis_dup` (         `cmb_id` int(5) not null auto_increment,         `class_id` int(10) not null,         `division` varchar(3) not null,         `boys` varchar(100) not null,         `girls` varchar(100) not null,         `subject_name` varchar(20) not null,         `exam_name` varchar(5) not null,         `term_id` int(3) not null,         primary key (`cmb_id`)         ) engine=innodb  default charset=latin1 auto_increment=1 ; "  

use 2 case (one female, 1 male) , inner join

insert cmparitive_analysis_dup(subject_name, boys, girls) select a.subject_name,    sum(case when a.gender = 'f' a.value else 0 end),    sum(case when b.gender = 'm' b.value else 0 end) test_comparitive_analysis  inner join test_comparitive_analysis b on(a.cmb_id = b.cmb_id) group a.subject_name 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -