MySQL笔记2

显示所有数据库:show databases;
创建数据库:create database 数据库名;
删除数据库:drop database 数据库名;
对数据库进行操作:use 数据库名字;
显示该数据库下的表:show tables;
创建表:create table tablename(id int auto_increment,username varchar(30),primary key(id));
查看表结构:desc tablename;
删除表中指定id元素: delete from student where id=2;
插入表数据:insert into tablename(username,password,registerdate) value(‘shu’,‘0623’,‘2021-2-3’);
获取该表中的内容(数据):select * from tablename;
删除表属性:alter table 表名 drop column 属性名字;
在表中添加属性:alter table 表名 add 属性int after password(在password属性后面);
更改指定表中指定id中某属性的值: update 表名set 属性='266’where id=1;
±—±---------±---------±------±-------------+
| ID | username | password | money | registerdate |
±—±---------±---------±------±-------------+
| 1 | hhj | 456 | 266 | NULL |
| 2 | Wt | 123 | 300 | NULL |
| 3 | 集合 | 0623 | NULL | 2021-06-23 |
±—±---------±---------±------±-------------+
查找大于=255的的数值:select*from users where money>=255;

±—±---------±---------±------±-------------+
| ID | username | password | money | registerdate |
±—±---------±---------±------±-------------+
| 1 | fgd | 456 | 266 | NULL |
| 2 | Wyt | 123 | 300 | NULL |
±—±---------±---------±------±-------------+
2 rows in set (0.01 sec)
限制查找前两行数据:select*from users limit 2;
根据钱 正序排列:select *from mytable order by money;
查找前两行的名字个钱 select username,money from mytable limit 2;
倒序查找排列:select from mytable order by money desc;
前五行正序排列: select
from mytable order by money limit 5;
前五行倒序: select *from mytable order by money desc limit 5;
select username,money from mytable order by money desc limit 3;
±---------±------+
| username | money |
±---------±------+
| dhsa | 88 |
| sdh | 66 |
| sish | 56 |
±---------±------+
3 rows in set (0.00 sec)

第二行到第五行排序select *from mytable order by money desc limit 2,5;
显示排序号后的第一行数据: select *from mytable order by money desc limit 1
排序并显示钱数大于三十小于五十:select *from mytable where money >30 and money <80 order by money;
倒序:select from mytable where money >30 and money <80 order by money desc ;
显示不等于sdh的表数据并倒序:select from mytable where username!=‘sdh’ order by money desc;
查找属性中含有‘宋’字的名字(%是多少字符都行):selec t
from student where name like ‘宋%’;
查找属性中含有‘宋’字的名字(_是一个_代表一个字符): select
from student where name like ‘宋_’;
distinct去重;

摘选出skill前两个字符:select distinct left(skill,2)from people;
去掉名字相同的:select distinct concat(username)from people;

Id为二的名字有多长:select distinct length(username)from people where id=2;
倒序:select reverse(username)from people where id=2;
更改指定数字:select username,replace(username,‘马’,‘李’)from people where id=16;
只输出表中所有姓名和功能属性:select concat(username,skill)from people;
输出含有某属性的个数:select time ,count(*)from people group by time having time =‘远古时代’;
取余:select mod(7,8);
开根:select sqrt(coin)from people where id=2;
现在日期时间规定好属性名字:select now() as nowtime;
现在日期时间:select now();
现在时间: select curtime();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卿屿­­­­­­­-轻尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值