Sql语句中IN等方面的用法
2007-08-02 10:28
369 查看
导读:
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
本文转自
http://hi.baidu.com/qzrc/blog/item/ff7ad688bc548394a4c272ce.html
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
本文转自
http://hi.baidu.com/qzrc/blog/item/ff7ad688bc548394a4c272ce.html
相关文章推荐
- Sql语句中IN等方面的用法
- sql语句中的 in 、not in 、exists、not exists 详细用法说明和差别----not in失效
- SQL语句中in not in exits not exits用法比较
- 【PB】在PB中嵌入式sql语句"in"的用法
- ibatis中配置sql语句in关键字的用法(遍历list和数组)。
- sql语句中exists和in用法的区分
- sql语句中的 in 、not in 、exists、not exists 详细用法说明和差别----not in失效
- SQL语句中IN的用法
- 项目中的sql语句涉及到取集合时(即in(...))的用法foreach
- ibatis sql语句in 的用法
- linq to ef(相当于sql中in的用法)查询语句
- oracle sql 语句 in 与EXIST用法比较
- SQL语句中IN的用法
- SQL中IN和EXISTS用法的区别
- oracle: OCA-047-题解与实验(10)--SQL语句中to_date的用法
- Mybatis中动态SQL语句中的parameterType不同数据类型的用法
- beetl中sql的in语句
- sql语句中----删除表数据drop、truncate和delete的用法
- sql语句优化--用EXISTS替代IN、用NOT EXISTS替代NOT IN
- 探究SQL中Case语句用法