两个表的关联字段是姓名 希望的结果是 张三 男 信息一 李四 女 信息三 王五 男 空SQL code: SELECT U.*,I.信息 from USER U LEFT JOIN INFO I ON U.ID=I.ID
user表 id 姓名 性别 1 张三 男 2 李四 女 3 王五 男
info表 id 姓名 信息 1 张三 信息一 2 张三 信息二 3 李四 信息三 4 张三 信息四 5 李四 信息五 select m.姓名 ,m.性别 ,isnull(n.信息,'空') 信息 from [user] m left join info n on m.姓名 = n.姓名 如果是最开始的需求: select m.姓名 ,m.性别 ,isnull(n.信息,'空') 信息 from [user] m left join info n on m.姓名 = n.姓名
第一句: select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je from ht left join gfdm on ht.gfdm=gfdm.gfdm join jh on ht.htbh=jh.hth and ht.htbh not like'del%' and ht. ......