LabVIEW数据库-常用的SQL语句_MySQL


常用的SQL语句

DML数据操作语言

insert

insert into 表名 (列名1,列名2…)values (列值1,列值2…);
插入值

delete

delete from table where 列名 +判断条件
删除指定行
delete from table1 where aa=‘aa’ ;

update

update 表名 set 列名1=值1,列名2=值2,…where 列名=值n;
更新数据
update table1 set aa=‘aa’ where bb=‘334’;
update table set 列名 = now() where 列名 条件;
插入时间now日期时间,curdate日期,curtime时间
update table1 set dd = CURDATE() where aa = ‘323’;

select

select name1,name2… from database.table;
选中列
database.不加则代表当前数据库
select * from database.table;
选中所有列
select * from database.table limit 行数;
选中所有列,指定数量的行
select * from database.table order by 列名 desc;
选中所有列,以指定列进行排序。默认升序,desc降序
select distinct * from database.table;
查找唯一不同的值
select distinct aa,bb from table1 ;
select * from table where 列名+判断条件;
查找满足相应条件的值
select * from table1 where aa <> ‘a’;
select * from table where 列名+判断条件 and 列名+判断条件;
多列条件同时满足
select * from table1 where aa <> ‘a’ and bb=‘334’;
select * from table where 列名+判断条件 or 列名+判断条件;
多列条件中存在满足的
select * from table1 where aa <> ‘a’ or bb=‘334’;
select * from table1 where 列名 between 值1 and 值2;
满足某列在值1与值2之间
select * from table1 where aa between ‘a’ and ‘334’;
select * from table1 where 列名 like 值;
模糊搜索,‘j%‘以j开头的,’%j’以j结尾的,’%o’中间有o的
select * from table1 where bb like ‘%4’;
模糊搜索,_表示模糊掉一个字符
select * from table1 where bb like ‘__4’;
select * from table where table REGEXP 条件;
扩展正则表达式,模糊搜索,^开始,[]或者,$结束,.表示一个字符,…n个点表示n个字符
select * from table1 where bb REGEXP ‘^4’;
select * from table where table in(值1,值2…);
满足列在条件之中
select * from table1 where bb in (4,334);
select 列名 from as 别名 from table;
为列取别名
select aa as bieming from table1;
select * from table as 别名;
表取别名
select * from table1 as biao;
select table1.列名1,table2.列名1,table2.列名2…from table1,table2 where table1.列名=table2.列名;
在两个表中选择数据
select distinct table1.aa,table2.tt from table1,table2 where table1.aa=table2.aa;
select table1.列名,table2.列名 …from table1 join table2 orders on table1.列名=table2.列名;
在两个表中选择数据
select distinct table1.aa,table2.tt from table1 join table2 on table1.aa=table2.aa;
select table1.列名,table2.列名 …from table1 left join table2 orders on table1.列名=table2.列名;
在两个表中选择数据,即便右表没数据也返回值
select distinct table1.aa,table2.tt from table1 left join table2 on table1.aa=table2.aa;
select table1.列名,table2.列名 …from table1 right join table2 orders on table1.列名=table2.列名;
在两个表中选择数据,即便左表没数据也返回值
select distinct table1.aa,table2.tt from table1 right join table2 on table1.aa=table2.aa;
select 列名1,列名2…from table1 union select 列名1,列名2 …from table2;
在两个表中选择数据并合并结果集
select distinct aa,bb from table1 union select aa,tt from table2;
select * into outfile ‘文件’ from table;
当前选择的保存为文件
select * into outfile ‘D://2.txt’ from table1;
select count (列名) from table
返回不含null的行数
select count(cc) from table1;
select * from table where 列名 is null
选择为空的/不为空的
select * from table1 where aa is not null;
select AVG(列名)from table
AVG平均数MAX最大值MIN最小值
select AVG(cc) from table1;
select UCASE(列名) from table
UCASE大写LCASE小写
select UCASE(aa) from table1;
select left(列名,从左侧几位字符)from table
left从左侧截取几位字符right 从右截取
select left(aa,1) from table1;
select round(列名,指定第几位小数开始四舍五入)from table
四舍五入
select round(cc,1) from table1;
select mod(列名1,列名2)from table
求余数
select mod(cc,ff) from table1;
select now() from table;
返回当前日期时间
select now() from table1;
select sum(列名)from table;
求和
select sum(cc) from table1;
select 列名,function(列名)from table where 条件 group by列名
分组
select aa ,avg(cc)from table1 group by aa;分组完了求平均值

DDL数据定义语言

create

create table 表名(列名 数据类型 空或非空 排序方式, …,primary key(列名));
创建表
create table table6(ID integer not null, graduated tinyint(1) not null,weight double not null,birthday datetime not null,primary key (ID) );
create database 数据库名;
新建数据库
create database sb;
create table 新表名(select *from 旧表名);
创建表并复制数据
create table table33(select *from table1);
create view 视图名 as select 列名1,列名2…from table where 条件
创建视图
create view s as select aa,cc from table1;

alter

alter table 表名 add 列名 数据类型
增加列
alter table table1 add cc int;
alter table 表名 drop 列名
删除列
alter table table1 drop dd ;

drop

drop table 表名
删除表
drop table table33;
drop database 数据库名
删除数据库
drop database ;
drop view 视图名
删除视图
drop view s;

rename

truncate

DCL数据控制语言

commit

rollback

savepoint

grant

revoke

其他

show tables;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

斯金

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

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

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

打赏作者

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

抵扣说明:

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

余额充值