我有一张表格,其中列出了负责货币门槛的个人。表Thresholds
如下所示:
John Smith 5000.00
Carla Smith 3000.00
Anna Smith 1000.00
我正在尝试制作一个select语句,我可以在其中返回下一个最高阈值的个人姓名。所以我的订单是1500.00。我想要归还卡拉的名字,因为价值高于安娜,但我不想看约翰作为一个选择。
你会推荐什么?
答案 0 :(得分:1)
Declare @YourTable table (Name varchar(50),SomeValue int)
Insert Into @YourTable values
('John Smith',5000),
('Carla Smith',3000),
('Anna Smith',1000)
;with cte as (
Select *,RN=Row_Number() over (Order by SomeValue)
From @YourTable
Where SomeValue >= 1500
)
Select * from cte where RN=1
返回
Name SomeValue RN
Carla Smith 3000 1
或@James建议(如果有平局)
;with cte as (
Select *,Rnk=Dense_Rank() over (Order by SomeValue)
From @YourTable
Where SomeValue >= 1500
)
Select * from cte where Rnk=1
答案 1 :(得分:0)
使用var data = { "1F54716": [], "1258820b-guid": [ { "value": "true", "property": "", "say": "Hello", }, { "value": "false", "property": "", "say": "Hello", } ], },
count;
// filter all properties
Object.keys(data).forEach(function (k) {
data[k] = data[k].filter(function (a) {
return a.value === "true";
});
});
// count
count = Object.keys(data).reduce(function (r, k) {
return data[k].reduce(function (rr, a) {
return rr + +(a.say === 'Hello');
}, r);
}, 0);
console.log(data);
console.log(count);
:
TOP