sql - mysql: truncating a field and aggregating the data in another table -


i have table has date in form of date time.

mysql> select * topsmsspammers_hour limit 1; +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | date                | spam | suspect | clean | spammer      | spam_campaign_id                            | messagetype | policy | issenderpolicy | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | 2013-06-11 23:00:00 |    1 |       0 |     0 | +12073708065 | notset|message35392herbisreallyworkingrealy |           4 |      1 |              1 | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ 1 row in set (0.00 sec)  mysql> 

i want use data in table populate aggregate day date table exact same column names date truncated (and counts changed reflect change) first identified select query truncate data need:

mysql> select substring_index(date, ' ', 1) date, sum(spam) spam, sum(suspect) suspect, sum(clean) clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy topsmsspammers_hour group date, spammer, spam_campaign_id, messagetype, policy, issenderpolicy limit 1; +------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | date       | spam | suspect | clean | spammer      | spam_campaign_id                            | messagetype | policy | issenderpolicy | +------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | 2013-06-11 |    1 |       0 |     0 | +12073708065 | notset|message35392herbisreallyworkingrealy |           4 |      1 |              1 | +------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ 1 row in set, 1 warning (1.66 sec)  mysql> 

i tried use select query populate new table truncated date not inserted. rather original date inserted:

mysql> insert topsmsspammers_day (date, spam, suspect, clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy) select substring_index(date, ' ', 1) date, sum(spam) spam, sum(suspect) suspect, sum(clean) clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy topsmsspammers_hour group date, spammer, spam_campaign_id, messagetype, policy, issenderpolicy limit 1; query ok, 1 row affected, 1 warning (1.68 sec) records: 1  duplicates: 0  warnings: 1  mysql> select * topsmsspammers_day limit 1;                                                                +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | date                | spam | suspect | clean | spammer      | spam_campaign_id                            | messagetype | policy | issenderpolicy | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | 2013-06-11 00:00:00 |    1 |       0 |     0 | +12073708065 | notset|message35392herbisreallyworkingrealy |           4 |      1 |              1 | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ 1 row in set (0.00 sec)  mysql> 

i tried changing data have different name populating new table still resulted in full date getting inserted table:

mysql> insert topsmsspammers_day (date, spam, suspect, clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy) select substring_index(date, ' ', 1) daydate, sum(spam) spam, sum(suspect) suspect, sum(clean) clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy topsmsspammers_hour group daydate, spammer, spam_campaign_id, messagetype, policy, issenderpolicy limit 1; query ok, 1 row affected (1.75 sec) records: 1  duplicates: 0  warnings: 0  mysql> select * topsmsspammers_day limit 1; +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | date                | spam | suspect | clean | spammer      | spam_campaign_id                            | messagetype | policy | issenderpolicy | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ | 2013-06-11 00:00:00 |    1 |       0 |     0 | +12073708065 | notset|message35392herbisreallyworkingrealy |           4 |      1 |              1 | +---------------------+------+---------+-------+--------------+---------------------------------------------+-------------+--------+----------------+ 1 row in set (0.00 sec)  mysql> 

i tried changing name in insert fell on over name not being field in new table:

mysql> insert topsmsspammers_day (daydate, spam, suspect, clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy) select substring_index(date, ' ', 1) daydate, sum(spam) spam, sum(suspect) suspect, sum(clean) clean, spammer, spam_campaign_id, messagetype, policy, issenderpolicy topsmsspammers_hour group daydate, spammer, spam_campaign_id, messagetype, policy, issenderpolicy limit 1; error 1054 (42s22): unknown column 'daydate' in 'field list' mysql> 

what missing? how can insert truncated aggregated data new table?

a

it looks 2013-06-11 23:00:00 changed 2013-06-11 00:00:00 maybe problem datatype a

check datatype of column, guess using datetime. change date datatype


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. ? -