1. Clarify the goals of data analysis
Count the number of orders generated every hour
2 Create a table to save data analysis results
create table app_hour_orders(
id int primary key auto_increment,
daystr varchar(20),
hourstr varchar(20),
cnt int
);
3. Write SQL statements for data analysis
select
substring(createTime,1,10) as daystr,
substring(createTime,12,2) as hourstr,
count(*) as cnt
from ods_finebi_orders
group by
substring(createTime,1,10),substring(createTime,12,2)
order by hourstr;
4 Load data into the results table
insert into app_hour_orders
select
null,
substring(createTime,1,10) as daystr,
substring(createTime,12,2) as hourstr,
count(*) as cnt
from ods_finebi_orders
group by
substring(createTime,1,10),substring(createTime,12,2)
order by hourstr;