我正在sql server中编写一个VIEW,并加入了几个带有内连接的表。
问题。
使用带有多重内连接的select语句,添加' Top 1'的正确语法是什么?或者选择第一条记录并按
添加订单谢谢
select top 500
rtrim(pendk_policy) as Id
,case (pendk_company) when '17' then 'BNR' when 'WP' then 'PENN' end as Company
,case rtrim(pendk_policy) when '' then '--' else rtrim(pendk_policy) end as PolicyNumber
,'InForce' as [Type]
, (
case
when WPOLC_CONTRACT_CODE = 'A' then 'Active'
when WPOLC_CONTRACT_CODE = 'T' then 'Terminated'
when WPOLC_CONTRACT_CODE = 'P' then 'Pending'
when WPOLC_CONTRACT_CODE = 'S' then 'Suspended'
when WPOLC_CONTRACT_CODE = 'H' then 'On Hold'
end
) as [Status]
, top 1 rtrim(nameRela.wname_individual_first) + ' '+ rtrim(nameRela.wname_individual_middle) + ' ' + rtrim(nameRela.wname_individual_last) as Customer
from
WPOLC_TABL wpolc
inner join WRELA_TABL wrela on (wrela.WRELA_COMPANY_CODE = wpolc.WPOLC_COMPANY_CODE and wrela.WRELA_POLICY_NUMBER = wpolc.WPOLC_POLICY_NUMBER and wrela.WRELA_RELATE_CODE = 'sa')
inner join WRELA_TABL custRela on (custRela.WRELA_COMPANY_CODE = wpolc.WPOLC_COMPANY_CODE and custRela.WRELA_POLICY_NUMBER = wpolc.WPOLC_POLICY_NUMBER
and custRela.WRELA_RELATE_CODE in ('in', 'ji' , 'je')) order by custRela.WRELA_RELATE_CODE
inner join wname_tabl nameRela on (custRela.WRELA_COMPANY_CODE = nameRela.WNAME_COMPANY_CODE and custRela.WRELA_NAME_ID = nameRela.WNAME_NAME_ID )
order by nameRela.WNAME_INDIVIDUAL_LAST
inner join PENDKEY_TABL pk on (wrela.WRELA_COMPANY_CODE = pk.PendK_company and wrela.WRELA_POLICY_NUMBER = pk.PENDK_POLICY)
答案 0 :(得分:0)
订单应该在查询中排在最后。基本格式为:
Select
From
inner join
where
order by