欢迎大家一起讨论测试, 希望多点认识热爱测试的朋友.让在测试的路上增添热闹.

Sql语句中IN等方面的用法(转)

上一篇 / 下一篇  2013-08-30 23:02:36 / 个人分类:数据库

导读:
select * from txt1
select * from txt2
select * from txt1 where name in (select name from txt2 where chk = 0)
select * from txt1 where name not in (select name from txt2 where chk = 0)
select * from txt1 inner join txt2 on txt1.name = txt2.name
select * from txt1 left join txt2 on txt1.name = txt2.name
select * from txt1 right join txt2 on txt1.name = txt2.name
select * from txt1,txt2 where txt1.name = txt2.name Order By txt2.ID Desc
select Txt1.name,Sum(Txt1.Sumint) from txt1,txt2 where txt1.name =txt2.name Group by txt1.name
select count(Txt1.name),sum(sumint) from txt1,txt2 where txt1.name =txt2.name having sum(sumint)<10
select count(Txt1.name),sum(sumint) from txt1,txt2 where txt1.name =txt2.name having Sum(sumint) >50
select * from txt1,txt2 where txt1.name <>txt2.name Order by Txt1.Name compute Sum(sumint) by txt1.name
insert into txt3 select name,Sumint from txt1
In:等值连接,用来查找多表相同字段的记录
Not In:非等值连接,用来查找不存在的记录
Inner join:内连接,主要用来查找都符合条件的记录
Left join:左连接,主要用来查找左边有,右边没有的用空值表达
Right join:右连接,主要用来查找右边有,左边没有的用空值表达
Order By:升序 Asc 降序 Desc
Group By:分组排序 按字段分组(如按班级分),使用的都要有集合函数存在
Having :对分组条件进行判断,使用都要确保每个字段都要用集合函数
COMPUTE BY:子句使您得以用同一 SELECT 语句既查看明细行,又查看汇总行。可以计算子组的汇总值,也可以计算整个结果集的汇总值。
行聚合函数名称;例如,SUM、AVG、MIN、MAX 或 COUNT
insert into:主要把查询的语句插入到新表。
txt1表的数据
ID Name SumInt
1 张三 55
2 李四 85
3 王五 85
4 赵六 855
txt2表的数据
ID Name Chk
1 张三 0
2 李四1 1
3 王五 0
4 赵六 0

TAG:

 

评分:0

我来说两句

Open Toolbar