如何仅在 sql 服务器中第 3 名赔率在 5 到 6 美元之间时显示第 1 个 FAV

How to show 1st FAV only if 3rd fav place odds are between 5 and 6 dollars in sql server

这适用于 Microsoft sql server management studio 2008

你好,我有以下 运行 比赛的数据:

Name /fav / odds /Place
John / 3rd / 5.21 / 1st
Bob / 1st / 3.11 / 2nd
paul / 6th /10.10 / 3rd
ken / 4th / 6.11 / 4th
ted / 7th /20.44 / 5th
julie/ 8th /100.00/ 6th
rob / 9th / 22.11/ 7th
rex /10th / 33.55/ 8th
rod / 2nd / 4.11 / 9th
nub / 5th / 7.34 / 10th

1) 我知道如何在没有其他条件的情况下显示第一个最爱 -> 结果:(Bob 1st / 3.11 / 2nd)

2) 但是我如何显示第一个 FAV(Bob 1st / 3.11 / 2nd) 仅当第三个 fav (John 3rd / 5.21 / 1st and 6 dollars) ODDS 在 5 到 6 美元之间,它们是为了这个工作。

结果(鲍勃第一名/3.11/第二名)

试试这个,

select * from table1 where fav='1st' 
and exists
(select name from 
table1 
where fav='3rd' and odd between 5 and 6)