求一个数据库SQL语句句

如果对您有帮助的话,帮忙点个赞哦!!!SQL Joins1、select * from tableA A inner join tableB B on A.key=B.key2、select * from tableA A Left join tableB on A.key=B.key3、select * from tableA A right join tableB B on A.key =B.key4、select * from tableA A left join tableB B on A.key=B.key where B.key is null5、select * from tableA A right join tableB B on A.key = B.key where A.key =B.key where A.key is null6、select * from tableA A full join tableB on A.key =B.key7、select * from tableA A full outer join tableB B on A.key =B.key where A.key is null or B.key is null基本查询语句1、 使用select语句查询一个数据表Select * from 表名2、 查询表中的一列或多列Select 字段,字段 from 表名3、 从一个或多个表中获取数据Select 表1.字段1,表1.字段2, 表2.字段1,表2.字段2,from 表名1,表名2单表查询1、 查询所有字段Select * from 表名2、 查询指定字段Select 字段 from表名;3、 查询指定数据Select * from 表名 where 字段=“值”4、 带关键字IN的查询Select * from 表名 where 条件 IN(元素1,元素2,…);5、 带Between and的范围查询Select * from 表名 where 条件 [NOT] between 取值1 And 取值 2;6、 带LIKE的字符匹配查询Select * from 表名 where 字段 like ‘%值%’7、 用关键值IS Null查询空值Select 字段 from 表名 where 字段 is null;8、 带关键字and的多条件查询Select * from 数据表名 where 条件1 and 条件2 [and 条件表达式n]9、 带关键字OR的多条件查询Select * from 数据表名 where 条件1 or条件2[or 条件表达式n]10、用关键字DISTINCT去除结果中的重复行Select distinct 字段名 from 表名11、用关键字order by 对查询结果排序ORDER BY 字段名【ASC|DESC】Select * from 表名 order by 字段 desc12、用关键字GROUP BY 分组查询1、使用关键字group by来分组Select 字段名 from 表名 group by 字段2、关键字Group BY 与Group_CONCAT()函数一起使用Select 字段名 GROUP_CONCAT(字段名)from 表名 GROUP BY 字段名3、 按多个字段进行分组Select 字段名 from 表名 group by 字段,字段13、用关键字limit限制查询结果的数量Select * from 表名 order by 字段 asc limit n (n表示查询的个数)1、 count()函数Select count(*) from 表名2、 sum()函数Select sum(字段)from 表名3、 AVG()函数Select AVG(字段) from 表名4、 MAX()函数Select MAX(字段) from 表名5、 MIN()函数Select MIN(字段) from 表名连接查询1、 内连接查询Select 字段1,字段2 from 表名1,表名2 where 表名1.字段1=表名2.字段22、 外链接查询Select 字段 from 表名1 left|right join 表名2 on 表名1.字段=表名2.字段3、 复合条件连接Select 字段 from 表名1 left|right join 表名2 on 表名1.字段=表名2.字段 and 值>n子查询1、带关键字IN的子查询Select * from 表名 where 字段 IN(select 字段 from 表名)2、 带比较运算符的子查询(将值进行比较)Select 字段 from 表名 where 字段>=(select 字段 from 表名)3、带关键字EXISTS的子查询(判断某个值是否存在)Select 字段 from 表名 where exists(select 字段 from 表名 where 字段=值)3、 带关键字ANY的子查询(判断第一个表的值都小于第二个标的值)Select 字段 from 表名 where 字段<ANY(select 字段 from 表名)5、带关键字ALL的子查询(判断第一个表的值都大于等于第二个标的值)Select 字段 from 表名 where 字段>=ALL(select 字段 from 表名)合并查询1、 UNION(将2个表进行合并并查询)Select 字段 from 表名UNIONSelect 字段 from 表名

我要回帖

更多关于 数据库SQL语句 的文章

 

随机推荐