易截截图软件、单文件、免安装、纯绿色、仅160KB

sql查询

如何将两个SQL查询语句的查询结果并合在一起?

如:
第一个查询语句为:select * from a
第二个查询语句为:select * from b
则并合这两个语句的语句是否为:select * from (select * from a,select * from b)???
这样好像不对。
如果两表的结构相同的话
select * from a
union all
select * from b

横向left join
纵向 union all

SQL code:
select * from a left join b on a.id=b.id

select * from a
union all
select * from b


引用
如何将两个SQL查询语句的查询结果并合在一起?

如:
第一个查询语句为:select * from a
第二个查询语句为:select * from b
则并合这两个语句的语句是否为:select * from (select * from a,select * from b)???
这样好像不对。


如果两表字段,类型相同.
select * from a
union all
select * from b


如果两表字段,类型不相同.
更改类型和名称.
例如:

select id , name ... from a
union all
select cast(bid as int) , bname as name ... from b

或者是:

select a.* , b.* from a , b where a.关键字 = b.关键字
select a.* , b.* from a left join b on a.关键字 = b.关键字


A表为:
a_date     a_log  a_rs a_ys
2009-11-1 T 1


相关问答:

数据窗口动态修改Sql - PowerBuilder / DataWindow

为了满足数据查询的速度问题,我将一张数据量大的学生表按年度分成多个表
students_2008, students_2009然后我又做了一个模板表students_template,模板表中的字段和students_2008, students_2009一样,只不过是一个 ......

pl/Sql如何查询字符串包括%

pl/Sql如何查询字符串包括%, 
例如:TABLE a
columnA
'222'
'33%44'
如何查询表a中columnA字段中哪些行包含'%'
谢谢
select * from a
where columna like '%/%%' escape '/'

UP

SELECT * from a ......

如果写递归sql语句 - MS-SQL Server / 应用实例

有两个同样的表结构 
表结构如下:
  id(序号) parentid (父结点序号) name(结点名称)
 表1 记录 1 0 aaa
  2 ......

一条sql语句 - MS-SQL Server / 基础类

Course(C#,Cname,T#) 课程表 
SC(S#,C#,score) 成绩表 
Teacher(T#,Tname) 教师表 
题目:把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; 
 update SC set sco ......

SQL时间段问题

一个很奇怪的问题 
SQL code
select * from Gprs_DataInof 
--可以查到所有的数据
select * from Gprs_DataInof where DataTime between 1900-10-16 1:01:00' and '2009-10-20 1:01:00'
--一条数据 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号