我有这个记录:
{id : 1 , price : 5}
{id : 2 , price : "6"}
{id : 3 , price : 13}
{id : 4 , price : "75"}
我想构建一个查询,只获取具有“string”类型价格的记录
所以,它会得到:
{id : 2 , price : "6"}
{id : 4 , price : "75"}
答案 0 :(得分:4)
您可以使用$type
查询运算符执行此操作:
Declare @tblemployee table (name varchar(25),salary int)
Insert Into @tblemployee values
('max',40000),
('rob',40000),
('jon',40000),
('joseph',25000),
('mary',25000)
Select Name
,Salary = case when RN=1 then cast(Salary as varchar(25)) else '' end
From (
Select *
,RN = Row_Number() over (Partition By Salary Order By Name)
,DR = Dense_Rank() over (Order By Salary)
From @tblemployee
) A
Order by DR Desc,RN
如果你正在使用MongoDB 3.2+,你也可以使用字符串别名:
Name Salary
jon 40000
max
rob
joseph 25000
mary