我们有两张桌子:
答案 0 :(得分:0)
with T
as (select C.S_Id, C.Paid
from tbl_CustomerData as C
where c.Cust_Name = @CUST_NAME)
select
S.SERVICESS as Servicess,
isnull(T.Paid,0) as Paid
from tbl_Servicedata as S
left join T as T on T.S_Id = S.ID
order by isnull(T.Paid,0) desc
答案 1 :(得分:0)
在这种情况下使用LEFT JOIN,
select A.SRVC, COALESCE(A.Paid, 0) Paid
from tbl_CustomerData A left join tbl_Servicedata B on (A.S_Id = B.ID)
where A.Cust_Name = @CUST_NAME