Sql server query: how to select clients with more than 1 order

I am new to sql server and trying to select all clients who have more than 1 order. The table is as follows:

CREATE TABLE [dbo].[orders]( [customerid] [int] NULL, [orderid] [int] NULL ) ON [PRIMARY] GO INSERT [dbo].[orders] ([customerid], [orderid]) VALUES (1, 2) INSERT [dbo].[orders] ([customerid], [orderid]) VALUES (1, 3) INSERT [dbo].[orders] ([customerid], [orderid]) VALUES (2, 4) INSERT [dbo].[orders] ([customerid], [orderid]) VALUES (2, 5) INSERT [dbo].[orders] ([customerid], [orderid]) VALUES (3, 1) 
+4
source share
1 answer
 select customerid , count(*) as order_count from orders group by customerid having count(*) > 1 
+7
source

Source: https://habr.com/ru/post/1492227/


All Articles