日期:2014-05-17  浏览次数:20421 次

SQL语句 求教!
有一张表格 
姓名(SNAME) 出生日期(birthday) 入职日期(jointime)

A            1981                         1990
B            1981                         1991
C            1980                         1990
D            1981                         1991
E            1980                         1991

求得结果表为
姓名(SNAME1)姓名(SNAME2) 出生日期(birthday)  入职时间差(jointime1)
A           B                  1981                   1
A           D                  1981                   1
B           D                  1981                   0
C           E                  1980                   1

SQL语句怎么写,求教
sql

------解决方案--------------------
select t1.sname sname1,t2.sname sname2,t1.birthday,jointime1=t2.jointime-t1.jointime
from tb t1 join tb t2 on t1.birthday=t2.birthday and t1.sname<t2.sname