简体   繁体   中英

How to use WHERE COUNT in Cosmos DB

Is it possible to do a query such as...

SELECT COUNT(UniqueLastNames)
FROM (
SELECT COUNT(c)
FROM c
WHERE COUNT(c.lastName) > 2 AND COUNT(c.lastName) < 5 GROUP BY c.lastName
) AS UniqueLastNames

What it should do is give me all the people whose last name appears more than twice, but less than 5.

Problem is, cosmos won't let you do a function in a WHERE statement it says, any other way around it?

Got it to work with the following code...

SELECT COUNT(UniqueLastNames)
FROM (SELECT COUNT(1) AS lastName FROM c GROUP BY c.lastName) AS 
UniqueLastNames WHERE UniqueEmails.lastName > 2 AND UniqueEmails.lastName < 
5

... though it's so expensive on RUs at 137.86 RUs per request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM