高分求1sql语句,子查询,解决即给分!
有3个表:Ta,Tb,Tc
想根据表Tc.username来确定Ta和Tb中的记录,
表Ta中有字段Ta.username,Ta.age
表Tb中也有字段Tb.username,Tb.sex
我现在想取,Tc中username='我' 的Ta.age, 和 Tb.sex
如:
select Tc.id,
(SELECT age FROM Ta WHERE username='我' ) AS age,
(SELECT sex FROM Tb WHERE username='我') AS sex
from Tc
where Tc.username='我'
这SQL 语句要怎么写啊?
注:Tc.id 必选
[解决办法]
SELECT TOP 100 PERCENT oid, ztid,a. mxtype, a.otitle, a. Mend, a. dtime, b.userncFROM dbo.Tsc,tzt a,tuser bWHERE userid = 2 and tsc.ztid=a.ztid and a.userid=b.tuseridORDER BY oid