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
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
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
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
表1 left join 表2 on 表1.userid=表2.userid left join 表3 on 表1.userid=表3.userid
其实提高速度的方法很简单,建立相应的聚集INDEX及非聚集INDEX即可,查询时间在
2秒左右。
10001 乐乐 怎样写令查询出来的记录不重复?
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