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

sql连接(内连接、外连接、全连接)

现有table_for_report_1和table_for_report_2,详情如下:
table_for_report_1有num字段,c1,c2,c3字段。
数据如下:
    num                c1  c2  c3
1 15001346690 11 12 13
2 13329921100 21 22 23
3 18900000000 31 32 33
4 13811111111 41 42 43
table_for_report_2有num字段,c4,c5字段。
数据如下:
    num                c4  c5 
1 13822222222 34 35
2 15001346690 14 15
3 13811111111 24 25
 
内连接:
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num=t2.num
结果:
    num                c1  c2 c3 c4 c5
1 15001346690 11 12 13 14 15
2 13811111111 41 42 43 24 25
外连接(左外连接和右外连接):
1)左外连接:
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num=t2.num(+)
或者
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1 left outer join table_for_report_2 t2
on (t1.num=t2.num)
结果:
    num                c1  c2 c3 c4 c5
1 15001346690 11 12 13 14 15
2 13811111111 41 42 43 24 25
3 18900000000 31 32 33  
4 13329921100 21 22 23  
2)右外连接:
select t2.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num(+)=t2.num
或者
select t2.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_rep


相关文档:

sql内置函数

一般地,日期格式说明符是不太敏感的。然而,当为了显示而说明日期格式、对于文本数据中的说明符等情况下,它就变得比较务实、具体了。以月份的名字为例,通过下面引用的结果解释一下该情况的效果:
TO_CHAR(SYSDATE,’MONTH’)=NOVEMBER
TO_CHAR(SYSDATE,’Month’)=November
TO_CHAR(SYSDATE,&rsq ......

SQL JOIN之完全用法

最近在做mysql的性能忧化,做到多表连接查询,比较头疼,看了一些join的资料,终于搞定,这里分享出来!
外联接。外联接可以是左向外联接、右向外联接或完整外部联接。    
  在   from   子句中指定外联接时,可以由下列几组关键字中的一组指定:  
 &n ......

SQL Server中各数据类型尺寸(Byte)


数据类型
存储尺寸
描述
bigint
8 bytes
 
integer
4 bytes
 
smallint
2 bytes
 
tinyint
1 byte
 
bit
1 byte
 
numeric(p,s)
decimal(p,s)
dec(p,s)
19 bytes
 
money
8 bytes
 
float
8 bytes
 
real
4 bytes
 
datetime
8 bytes
 
nvarchar(n)
2*长度 bytes
 
nte ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号