guanxf

我的博客:http://blog.sina.com.cn/17learning

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  71 随笔 :: 1 文章 :: 41 评论 :: 0 Trackbacks
LEFT JOIN 关键字语法:
SELECT column_name(s) 
FROM table_name1
LEFT JOIN
table_name2
ON
table_name1.column_name=table_name2.column_name

高级应用:
SELECT  	
had.deptTypeId as deptTypeId
,hdt.typeName as deptTypeName
,had.id as deptID
,had.deptName as deptName
,isnull(sg.siteGoalPoint,0) as siteGoalPoint
,isnull(sg.supGoalPoint,0) as supGoalPoint
from
--单位
(select a.deptTypeId,a.id,a.deptName
from HD_ACT_DEPT a
where 1 = 1
and deptTypeId = 'null'
) as had
LEFT JOIN
--单位类型
HD_DEPT_TYPE hdt
ON had.deptTypeId = hdt.id
LEFT JOIN
--任务完成情况统计表
(select a.siteGoalPoint,a.supGoalPoint,a.deptTypeId,a.deptID
from cms_sup_submit_goal a
where a.year = '2013'
) as sg
on had.deptTypeId = sg.deptTypeId and had.id = sg.deptID
ORDER BY had.deptTypeId, had.id
多表查询:
select s.id,s.name,s.sname from 
singer s, tb_su su
where s.id=su.sid  and  su.userid='1'
posted on 2013-03-28 23:41 管先飞 阅读(440) 评论(0)  编辑  收藏 所属分类: Database

只有注册用户登录后才能发表评论。


网站导航: