MySQL各種姿勢操作

2021-09-03 07:15:57 字數 3377 閱讀 4521

alter table teacherinfo  modify *** varchar(4) after birthday;
alter table teacherinfo change column num t_id int(10);
alter table teacherinfo drop column address;
alter table teacherinfo add column wages float;
alter table teacherinfo rename teacherinfoinfo;
create table worker (

id int(4) primary key not null,

num int(10) not null unique,

d_id int(4) ,

name varchar(20) not null,

*** varchar(4) not null,

birthday date ,

address varchar(50),

foreign key(d_id) references department(d_id)

);

show create table worker;
外來鍵約束名可以通過上一條語句檢視

alter table worker drop foreign key worker_ibfk_1;
updata table teacherinfo set birthday='1982-11-08' where num=1003;
delete from teacherinfo  where num=1002;
查詢 bumen 表中的第 4、5 條資料。limit 第乙個引數表示查詢開始的下標(從 0 開始),第二個引數表示查詢多少條資料。

select * from bumen limit 3,2;
查詢 yuangong 表中年齡在 25 - 30 之間的資料。

select * from yuangong where birthday >= 25 and birthday <= 30;
select d_id, count(d_id) from yuangong group by d_id;
根據部門查詢每個部門的最高工資

select d_id,max(salary) from yuangong group by d_id;
以左邊的資料表為準進行聯合查詢

select * from bumen left join yuangong on bumen.d_id=yuangong.d_id;
按部門分組,並計算每個部門的工資和

select d_id, sum(salary) from yuangong group by d_id;
desc 引數表示降序,去掉引數公升序排序

select * from yuangong order by salary desc;
drop index index_name on table_name;
alter table table_name drop index index_name;
alter table table_name frop primary key;
desc table_name;
create view info_view as select id, name, ***, address from work_info;
desc view_name;
update vire_name set ***='男' where id=4;
drop view view_name;
delimiter //

create procedure pfood_price_count( in price_info1 float,in price_info2 float, out count)

begin

select count(*), sum(price) into count,@sm from food where price between price_info1 and price_info2;

end;//

delimiter ;

call pfood_price_count(2, 18, @cnt)

select cnt;

delimiter //

create function pfood_price_count(price_info1 float,price_info2 float)

returns int

deterministic

begin

declare cnt int(4);

declare sm float;

select count(*), sum(price) into cnt,sm from food where price between price_info1 and price_info2;

return cnt;

end;//

delimiter ;

select pfood_price_count(2, 18)

delimiter //

create trigger 觸發器名字 after|before 型別(insert|delete|update|...)

on 表名 for each row

begin

觸發器執行的sql語句

end;//

delimiter ;

匯出 sql 型別檔案,可以通過改字尾名來改變檔案型別

mysqldump -u root -p dbname tablename > d:\backup\student.sql
mysql -u root -p dbname < d:\backup\student.sql

python列表各種切片姿勢

順著切,反著切,想怎麼切就怎麼切,但是別被坑。mylist 1,2,3,4,5,6,7,8,9 print mylist 2 7 2 3,5,7 print mylist 7 2 1,3,5,7 print mylist 2 2 3,5,7,9 print mylist 2 9 2 3,5,7,9 ...

各種MySQL混亂操作

多資料插入表 insert into es status s touroperator,iff objektlog,iff mit describe,iff ohne describe values jum select number from jumpreview where id like 2 ...

單例模式的各種姿勢

餓漢式 基於classloder機制避免了多執行緒的同步問題,不過,instance在類裝載時就例項化 public class singleton public singleton getinstance 懶漢式 public class singleton public static synch...