SELECT a.username,datediff(yy, a.birthday ,getdate()) AS 年龄 b.e_name,c.w_name 
FROM 用户基本信息表 a JOIN 教育信息表 b ON a.userid=b.userid
                      JOIN 工作经验表 c ON a.userid=c.userid
WHERE datediff(yy, a.birthday ,getdate()) BETWEEN 25 AND 30

解决方案 »

  1.   

    select a.username,datediff(year,a.birthday,b.s_time) as s_time,datediff(year,a.birthday,b.e_time) as e_time,b.e_name
    from 表一 a ,表二 b
    where a.userid=b.userid
    union all
    select c.username,datediff(year,c.birthday,d.s_time) as s_time,datediff(year,c.birthday,d.e_time) as e_time,d.w_name
    from 表一 c ,表三 d
    where c.userid=d.userid
      

  2.   

    select a.username,datediff(year,a.birthday,b.s_time) as s_time,datediff(year,a.birthday,b.e_time) as e_time,b.e_name,null as w_name
    from 表一 a ,表二 b
    where a.userid=b.userid
    union all
    select c.username,datediff(year,c.birthday,d.s_time) as s_time,datediff(year,c.birthday,d.e_time) as e_time,null as e_name,d.w_name
    from 表一 c ,表三 d
    where c.userid=d.userid
      

  3.   

    select 表1.username,datediff(yy,birthday,getdate()) age,表2.e_name,表3.w_name from 
    表1 left join 表2 on 表1.userid=表2.userid left join 表3 on 表1.userid=表3.userid
      

  4.   

    myflok(阿棋) Happiness(乐乐)  happydreamer(小黑) 各位:可以不可以利用存储过程提高速度?存储过程如何写? 还有可以不可以建一个中间视图??
      

  5.   

    查询很容易解决,关键是如果各表中记录超过20万条后,一个查询可能要2分钟以上。
    其实提高速度的方法很简单,建立相应的聚集INDEX及非聚集INDEX即可,查询时间在
    2秒左右。
      

  6.   

    myflok(阿棋) Happiness(乐乐)  happydreamer(小黑) 各位:查询出来的记录都是重复的,例如:10001   乐乐   
    10001   乐乐   怎样写令查询出来的记录不重复?
      

  7.   

    select distinct a.username,datediff(year,a.birthday,b.s_time) as s_time,datediff(year,a.birthday,b.e_time) as e_time,b.e_name
    from 表一 a ,表二 b
    where a.userid=b.userid
    union all
    select distinct c.username,datediff(year,c.birthday,d.s_time) as s_time,datediff(year,c.birthday,d.e_time) as e_time,d.w_name
    from 表一 c ,表三 d
    where c.userid=d.userid