create table wa_amount as select
-> sum(case when amount<1000 then 1 else 0 end) as'0-999' ,
-> sum(case when amount<2000 && amount >999 then 1 else 0 end) as'1000-1999' ,
-> sum(case when amount<3000 && amount >1999 then 1 else 0 end) as'2000-2999' ,
-> sum(case when amount<4000 && amount >2999 then 1 else 0 end) as'3000-3999' ,
-> sum(case when amount < 5000 && amount >3999 then 1 else 0 end) as'4000-4999' ,
-> sum(case when amount < 6000 && amount >4999 then 1 else 0 end) as'5000-5999' ,
-> sum(case when amount < 7000 && amount >5999 then 1 else 0 end) as'6000-6999' ,
-> sum(case when amount < 8000 && amount >6999 then 1 else 0 end) as'7000-7999' ,
-> sum(case when amount < 9000 && amount >7999 then 1 else 0 end) as'8000-8999' ,
-> sum(case when amount < 10000 && amount >8999 then 1 else 0 end) as'9000-9999'
-> from sortamount;
用as 只复制结构、数据
用like,会复制所有,包括索引、外键;