日期:2014-05-19  浏览次数:20585 次

路过的进来帮忙看下
表A
buyid             sellid                     qu
1                             2                           浦东区
3                             4                           闵行区
5                           6                             徐汇区
表B
peopleid                           brithday
1                                                 1986.9.24
2                                                 1966.6.6
3                                                 1987.8.4
4                                                 1965.2.4
5                                                 1985.3.21
6                                                 1977.12.1

说明:buyid(买家)   和sellid(卖家)   分别和peopleid   相连.
结果
------------------
区域                       买家年龄                                                                   卖家年龄
---------------------------
浦东区                 当前时间-1986.9.24                   当前时间-1966.6.6
闵行区                 当前时间-1987.8.4                   当前时间-1965.2.4
  徐汇区               当前时间-1985.3.21                   当前时间-1977.12.1

------解决方案--------------------
create table #A (
buyid int,
sellid int,
qu varchar(20))

insert #A
select 1,2, '浦东 '
union all
select 3,4, '闵行区 '
union all
select 5,6, '徐汇区 '

create table #B (
peopleid int,
birthday varchar(20))

insert #B
select 1, '1986.9.24 '
union all
select 2, '1966.6.6 '
union all
select 3, '1987.8.4 '
union all
select 4, '1965.2.4 '
union all
select 5, '1985.3.21 '
union all
select 6,