實習生,TeamLeader給了那麼一個數據庫題目:
給了如下兩張獨立的表:
Person
Orders
要求從這兩張表中選出以下結果:
ItemCount是購買的總數!
求救!在線等!
select t.Id_p,t.LastName,COUNT(OrderNo) as ItemCount from
(
select t1.OrderNo,ISNULL(t1.Id_p,t2.Id_p) as Id_p,isnull(t2.LastName,'Unknown') as LastName from Orders t1
full join Person t2
on t1.Id_p = t2.Id_p
) t group by t.Id_p,t.LastName