×

常用sql语句大全 常用sql语句大全最新

前端技术网 前端技术网 发表于2024-01-18 20:12:19 浏览1100 评论0

抢沙发发表评论

一、最惊艳的sql查询语句

最惊艳sql查询语句

select*fromtable1where工资>2500and工资<3000//同上

常用sql语句大全 常用sql语句大全最新

select姓名fromtable1where性别='0'and工资='4000'

select*fromtable1wherenot工资=3200

select*fromtable1orderby工资desc//将工资按照降序排列

select*fromtable1orderby工资asc//将工资按照升序排列

二、sql关联表查询语句

一、外连接

1.左连接leftjoin或leftouterjoin

常用sql语句大全 常用sql语句大全最新

SQL语句:select*fromstudentleftjoinscoreonstudent.Num=score.Stu_id;

2.右连接rightjoin或rightouterjoin

SQL语句:select*fromstudentrightjoinscoreonstudent.Num=score.Stu_id;

3.完全外连接fulljoin或fullouterjoin

SQL语句:select*fromstudentfulljoinscoreonstudent.Num=score.Stu_id;

通过上面这三种方法就可以把不同的表连接到一起,变成一张大表,之后的查询操作就简单一些了。

而对于select*fromstudent,score;则尽量不使用此语句,产生的结果过于繁琐。

二、内连接

join或innerjoin

SQL语句:select*fromstudentinnerjoinscoreonstudent.Num=score.Stu_id;

此时的语句就相当于:select*fromstudent,scorewherestudent.ID=course.ID;

三、交叉连接

crossjoin,没有where指定查询条件的子句的交叉联接将产生两表的笛卡尔积。

SQL语句:select*fromstudentcrossjoinscore;

三、sql常用语句

很高兴来回答这个问题!

SQL常用语句

插入语句:

基本插入语句:

insertintotable_namevalues(value1,value2,value3,...);(table_name:表名称)

延伸插入语句:

从一个表**数据,然后把数据插入到一个已存在的表中:

insertintotable2select*fromtable1;

只**希望的列插入到另一个已存在的表中:

insertintotable2(column_name(s))selectcolumn_name(s)fromtable1;(column_names:列名)

2.查询语句:

基本查询语句:

select*fromtable_name----查询整个表selectcolumn_name,column_namefromtable_name;----查询表中的某一列

条件查询语句:

select*fromtable_namewheresome_column=some_valueorsome_column=some_value;

包含条件查询语句

select*fromtable_namewheresome_columnlike'%some_value%';

'%'--通配符:

xx%--以xx开头%xx--以xx结尾%xx%--有xx

3.删除语句:

deletefromtable_namewheresome_column=some_value;

4.更新语句:

updatetable_name

setcolumn1=value1,column2=value2,...

wheresome_column=some_value;

希望我的回答能够帮助到您!

四、sql语言中提供了哪些数据控制的语句

SQL语言中提供了两种数据控制(自主存取控制)的语句:

①GRANT(授权)语句例如:GRANTSELECT,INSERTON学生To张勇MTHCRANTOWION;

②REVOKE(收回)语句例如:REVOKEINSFRTON学生FORM张勇;

如果你还想了解更多这方面的信息,记得收藏关注本站。