sql server query: how to select customers with more than 1 order
sql, sql-server
Solution
select customerid
, count(*) as order_count
from orders
group by
customerid
having count(*) > 1
Problem
I am a sql server newbie and trying to select all the customers which have more than 1 orderid. The table looks 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) ```