小黑框如何连接mysql_珍藏版(cmd小黑框)数据库命令及操作
話不多說直接來,后續補充。
查看數據庫
show databases;
創建數據庫
create database 2018;
使用數據庫
use 2018;
查看數據庫中的所有表
show tables;
刪除數據庫
drop database 庫名;
create table student(
id int(10) auto_increment primary key,
name varchar(20) not null,
age int(5) default 16,
address char(50);
)
查看表設計
desc student;
添加數據 不按照字段體添加 所有字段需要定義
insert into student values(1,'張三',20,‘北京’);
不常用
按照字段添加
insert into student(name,age,address) values('李四',22,'北京');
insert into student(name) values('王五');
insert into student(name,age,address) values('趙六',29,'上海'),
('趙曉曉',24,'深圳'),('張紅',21,'北京'),('趙曉劉',23,'深圳');
刪除
delete from student where id =3;
delete from student where age=24;
delete from student where age=26 and ='趙六';
將表中的數據刪除 表仍然在
delete from student;
刪除表
drop table student;
修改
update student set age =26,address='上海' where name='王五';
update student set age =26,address='上海';
查詢* 表中的所有內容
select * from student;
查詢年齡在20-26之間的學生和年齡 between。。。and
select name,age from student where age between 20 and 26;
模糊查詢 like %代表多個字符
select name from student where name like '李%';
# _代表的為一個字符
select name from student where name like '李_';
select name from student where name like '%小%';
select name,age,address from student where name like '%六';
#查詢ID為偶數的學生信息
select * from student where id%2=0;
#查詢年齡不等于23的學生姓名和年齡 兩種寫法 != ,<>
select name,age from student where age !=23;
select name,age from student where age <>23;
#查詢id 為3,6,7,10 in包含
select * from student where id in(10,6,7,3);
#查詢年齡26 并且上海 and
select * from student where age = 26 and address='上海';
#查詢年齡26 或者來自上海
select * from student where age = 26 or address='上海';
#分頁 顯示第一頁代表的是索引 每頁顯示3條 每次顯示的條數
select * from student limit 3,3;
select * from student limit 4,2;
#查詢和李四年齡相同的學生姓名
select name from student where age = (select age from student where name='李四') and name !='李四';
#將年齡從小到大排序
select * from student order by age;
#大到小排序 order by.. desc order by asc(小到大)
select * from student order by age desc;
#聚合函數
count(),sum(),avg.max().min()
#統計表中總數量
select count(id) from student;
select count(*) from student;
select count(1) from student;
#年齡的總和
select sum(age) from student;
#平均年齡
select avg(age) from student;
#獲取最大值
select max(age) from student;
#獲取最小值
select min(age) from student;
#統計每個年齡分布有多少人 group by 分組
select count(id),age from student group by age;
#group by 需要與聚合函數聯合使用 having 必須與group by一起使用 為分組進行條件判斷
select count(id),age from student group by age having age>20;
將地址分組查詢
select count(id),address from student group by address;
統計同一地方人數大于3
select count(id),address from student group by address having count(id) >3;
select count(id) he,address from student group by address having he >3;
select count(id) as he,address from student group by address having he>3;
select count(id) as '總數',address from student group by address having 總數>3;
總結
以上是生活随笔為你收集整理的小黑框如何连接mysql_珍藏版(cmd小黑框)数据库命令及操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql技术内幕sampdb_MySQ
- 下一篇: newifi mini固件_如何在vmw