1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
create table cm.tb_user( id int, name varchar(255), age int, gender varchar(16) );
create table cm.tb_user( id int primary key, name varchar(255), age int, gender varchar(16), store_time datetime default now() );
create table cm.tb_user( id int primary key , name varchar(255) not null default 'NULL', age int, gender varchar(16), create_time datetime default now(), update_time datetime default now() );
create table cm.tb_user( id int primary key , name varchar(255) not null default '-', age int, gender varchar(16), store_time datetime default now(), update_time datetime default now() );
select min(age), max(age) from cm.tb_user where age < 40 group by gender;
select min(age), max(age) from cm.tb_user where age < 40 group by gender;
select id, name from cm.tb_user where age > 10 and id<=10010;
select id, name from cm.tb_user where 1=1 and age > 10 and id<=10010;
insert into cm.tb_user values (1001, 'Mike', 20, 'M');
insert into cm.tb_user (id, name, age, gender) values (1001, 'Mike', 20, 'M');
explain select * from cm.tb_user where id=1001 and age = 20;
select * from cm.tb_user;
select id, name from cm.tb_user;
delete from cm.tb_user where age > 35 limit 5;
delete from cm.tb_user where age <= 20; update cm.tb_user set age = age + 1;
begin; delete from cm.tb_user where age <= 20; update cm.tb_user set age = age + 1; commit;
insert into cm.data_count (dt, count) values ('2023-06-20', 101), ('2023-06-21', 231), ('2023-06-22', 170), ('2023-06-23', 146), ('2023-06-24', 187), ('2023-06-25', 123), ('2023-06-26', 221), ('2023-06-27', 101), ('2023-06-28', 103), ('2023-06-29', 122), ('2023-06-30', 144);
select dt, count from cm.data_count t1;
select t1.dt, t1.count * 1.0 / t2.count as ratio from cm.data_count t1 join cm.data_count t2 on datediff(t1.dt, t2.dt)=7;
|