我们将如何在SQL Server 2008中显示第一行列值。 [英] How we will display first row column value in SQL server 2008.
问题描述
详细信息样本......
S.No. Lead_id Tenure来源溢价
1 597 1年薪水9171
2 597 1年众议院妻子9171
3 597 1岁儿童1 9171
4 605 1年薪水8281.15
5 605 1年众议院妻子8281.15
6 605 1岁儿童1 8281.15
输出应该是这样的.---
S.No. Leadid Tenure来源溢价
1 597 1年薪水9171
2 597 1年众议院妻子0
3 597 1岁儿童1 0
4 605 1年薪水8281.15
5 605 1年家庭妻子0
6 605 1岁孩子1 0
注意: - 我想显示引导ID的第一行值,其他应该为零。
我试过的:
选择dc.premiumAmount作为'Premium',*来自tbl_LeadCampaignData_Prospect lcdp with(nolock)
left join tbl_GI_DC_NSTP dc with(nolock)on dc.LeadID = lcdp.LPID
Details Sample ...
S.No. Lead_id Tenure Source Premium
1 597 1 year Salaried 9171
2 597 1 year House wife 9171
3 597 1 year child 1 9171
4 605 1 year Salaried 8281.15
5 605 1 year House wife 8281.15
6 605 1 year child 1 8281.15
The output should be like this.---
S.No. Leadid Tenure Source Premium
1 597 1 year Salaried 9171
2 597 1 year House wife 0
3 597 1 year child 1 0
4 605 1 year Salaried 8281.15
5 605 1 year House wife 0
6 605 1 year child 1 0
Note:- I want to show first row value of lead id and other should be zero.
What I have tried:
select dc.premiumAmount as 'Premium', * from tbl_LeadCampaignData_Prospect lcdp with(nolock)
left join tbl_GI_DC_NSTP dc with(nolock) on dc.LeadID=lcdp.LPID
推荐答案
你可以试试这个:
You could try this:
SELECT z.Sno, z.LeadId, z.[Tenure Source], z.Premium
FROM
(
SELECT x.Sno, x.LeadId, x.[Tenure Source], x.Premium
FROM
(
SELECT ROW_Number() Over (ORDER By Sno, LeadId) as Rowno,
Sno, LeadId, [Tenure Source], dc.premiumAmount as Premium
FROM tbl_LeadCampaignData_Prospect lcdp
LEFT JOIN bl_GI_DC_NSTP dc on dc.LeadID=lcdp.LPID
) as x
WHERE x.Rowno = 1
UNION
SELECT y.Sno, y.LeadId, y.[Tenure Source], y.Premium
FROM
(
SELECT ROW_Number() Over (ORDER By Sno, LeadId) as Rowno,
Sno, LeadId, [Tenure Source], NULL as Premium
FROM tbl_LeadCampaignData_Prospect lcdp
) as y
WHERE y.Rowno > 1
) as z
ORDER BY z.Sno, z.LeadId
这篇关于我们将如何在SQL Server 2008中显示第一行列值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!