从返回值中过滤出一行

vjhs03f7  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(198)

我目前正在创建一个前5名的名单,这是价值排名。我路过 @InfoId = 12 返回我期望的值。但我不想让大家知道 @InfoId = @InformationId 例如,如果我把参数12作为 InfoId ; 我不想显示下表示例中的第一行`informationid=12。
下面是运行select查询时得到的一个返回示例

+------------------------------------+
| StateId InformationId CurrentValue |
+------------------------------------+
| 1             12           453231  |
| 1             10           394721  |
| 1             341          309425  |
| 1              21          308431  |
| 1              73          301342  |
+------------------------------------+

下面是一个我期待的例子:

+------------------------------------+
| StateId InformationId CurrentValue |
+------------------------------------+
| 1             10           394721  |
| 1             341          309425  |
| 1             21           309321  |
| 1             73           308431  |
| 1             62           301342  |
+------------------------------------+

这是我的密码:

@StateId int
    , @InfoId int    
    , @CurrentValue int  -- My new parameter 
AS
BEGIN       
        select      top 5
                    i.StateId,
                    i.InformationId,
                    i.CurrentValue,

        from        dbo.tblInformation i

        inner join  dbo.tblInformationAnalysis ia
        on          ia.StateId= i.StateId
        and         ia.InformationId= i.InformationId
        and         ia.CurrentValue= i.CurrentValue

        inner join  (
                    select  
                                StateId,
                                InformationId,
                                CurrentValue,
                    from        dbo.tblInformationAnalysis
                    where       StateId = @StateID

                    group by    StateId,
                                InformationId,
                                CurrentValue,
                    ) via
        on          via.stateId= ia.stateid
        and         via.informationId= ia.informationId
        and         via.CurrentValue= ia.CurrentValue

        inner join  dbo.tblRetailData r
        on          r.stateId= i.stateid
        and         r.informationId= i.informationId
        and         r.CurrentValue= i.CurrentValue

        inner join  dbo.tblCounty c
        on          c.stateId= r.stateid
        and         c.informationId= r.informationId
        and         c.CurrentValue = 1

        inner join  dbo.tblRetailDataPublished rp
        on          rp.stateId= i.stateId
        and         rp.informationId= i.informationId
        and         rp.CurrentValue = i.CurrentValue 

        inner join  dbo.RetailCollection rc
        on          rc.stateId= i.stateId
        and         rc.informationId= i.informationId

        where       i.StateId= @StateId
        and         p.InformationId = @InfoId

END

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题