Use group by 3

Source: Internet
Author: User

Description: based on the customer's country grouping, the query results show the country names and customer numbers with the number of customers greater than 5.
Query syntax:
VaR group = from C in CTX. MERs
Group C by C. Country into G
Where G. Count ()> 5
Orderby G. Count () descending
Select New
{
Country = G. Key,
Customer COUNT = G. Count ()
};
Corresponding SQL:
Select [T1]. [country], [T1]. [value3] as [number of customers]
From (
Select count (*) as [value], count (*) as [value2], count (*) as [value3], [t0]. [Country]
From [DBO]. [MERs] as [t0]
Group by [t0]. [Country]
) As [T1]
Where [T1]. [value]> @ P0
Order by [T1]. [value2] DESC
-- @ P0: Input int32 (size = 0; prec = 0; scale = 0) [5]

Description: queries the countries and cities covered by customers by country or city group.
Query syntax:
VaR anonymous group = from C in CTX. MERs
Group C by new {C. City, C. Country} into G
Orderby G. Key. Country, G. Key. City
Select New
{
Country = G. Key. Country,
City = G. Key. City
};
Description: queries the order quantity separately based on whether the condition is overweight.
Query syntax:
VaR groups by condition = from o in CTX. Orders
Group O by new {condition = O. Freight> 100} into G
Select New
{
Quantity = G. Count (),
Overweight = G. Key. condition? "Yes": "no"
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.