从返回值中过滤出一行

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

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

  1. +------------------------------------+
  2. | StateId InformationId CurrentValue |
  3. +------------------------------------+
  4. | 1 12 453231 |
  5. | 1 10 394721 |
  6. | 1 341 309425 |
  7. | 1 21 308431 |
  8. | 1 73 301342 |
  9. +------------------------------------+

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

  1. +------------------------------------+
  2. | StateId InformationId CurrentValue |
  3. +------------------------------------+
  4. | 1 10 394721 |
  5. | 1 341 309425 |
  6. | 1 21 309321 |
  7. | 1 73 308431 |
  8. | 1 62 301342 |
  9. +------------------------------------+

这是我的密码:

  1. @StateId int
  2. , @InfoId int
  3. , @CurrentValue int -- My new parameter
  4. AS
  5. BEGIN
  6. select top 5
  7. i.StateId,
  8. i.InformationId,
  9. i.CurrentValue,
  10. from dbo.tblInformation i
  11. inner join dbo.tblInformationAnalysis ia
  12. on ia.StateId= i.StateId
  13. and ia.InformationId= i.InformationId
  14. and ia.CurrentValue= i.CurrentValue
  15. inner join (
  16. select
  17. StateId,
  18. InformationId,
  19. CurrentValue,
  20. from dbo.tblInformationAnalysis
  21. where StateId = @StateID
  22. group by StateId,
  23. InformationId,
  24. CurrentValue,
  25. ) via
  26. on via.stateId= ia.stateid
  27. and via.informationId= ia.informationId
  28. and via.CurrentValue= ia.CurrentValue
  29. inner join dbo.tblRetailData r
  30. on r.stateId= i.stateid
  31. and r.informationId= i.informationId
  32. and r.CurrentValue= i.CurrentValue
  33. inner join dbo.tblCounty c
  34. on c.stateId= r.stateid
  35. and c.informationId= r.informationId
  36. and c.CurrentValue = 1
  37. inner join dbo.tblRetailDataPublished rp
  38. on rp.stateId= i.stateId
  39. and rp.informationId= i.informationId
  40. and rp.CurrentValue = i.CurrentValue
  41. inner join dbo.RetailCollection rc
  42. on rc.stateId= i.stateId
  43. and rc.informationId= i.informationId
  44. where i.StateId= @StateId
  45. and p.InformationId = @InfoId
  46. END

暂无答案!

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

相关问题