mysql - Iterate through a column and summarize findings -


i have table (t1) in mysql generates following table:

type    time    full 0       11      yes 1       22      yes 0       11      no 3       13      no 

i create second table (t2) summarize information found in t1 following:

type    time    num_full   total 0       11      1          2 1       22      1          1 3       13      0          1 

i want able iterate through type column in order able start summary, for-loop. types can value of n, rather not write n+1 where statements, have update code every time more types added.

notice how t2 skipped type of value 2? has been escaping me when try looping. want the types found have rows created in t2.

while direct answer nice, more helpful pointed sources figure out, or both.

this may want

create table t2 if not exists select type, time, sum(full) num_full, count(*) count t1  group type,time order type,time; 

depending on how want aggregate time column.

this starting point reference on group functions : https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
here create syntax https://dev.mysql.com/doc/refman/5.6/en/create-table.html


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -