作者diamondking (天剑流星)
看板Database
标题Re: [SQL ] 两个SQL语法要合并写在一起
时间Wed Sep 5 00:52:52 2007
※ 引述《TCH (最无价值单身汉)》之铭言:
: ※ 引述《diamondking (天剑流星)》之铭言:
: : 其实有比较简单的写法:
: : select a.StuName,
: : sum(datediff(hh,b.StartTime,b.EndTime)) Hours,
: : sum(datediff(hh,b.StartTime,b.EndTime))*100 Bonus
: : from Student a left outer join Spell b on a.StuID=b.SpellStuID
: : where b.YearMonth=200708 and a.UnitID=123
: : group by a.StuName
: : 大致上是这样,t-sql的语法不是很肯定,有错请指正
: 感谢...
: 不过这样的结果,在SQL Server执行却只有显示出现在Spell中的资料
: 我希望有此班级内全部人的资料,因为是 left join 所以右边会有 null,都要显示
: ps:我好像试出来了,明天再PO上来
: (因为是胡乱试出来的,自己现在也忘了作法 ^^|||)
我是用「left outer join」,不是「left join」喔…
outer join就能显示所有资料了,应该不会只有Spell内的资料,
你有空再试试好了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.167.120.203