D
D
dmitriev_maksimka2014-10-19 13:39:51
SQL
dmitriev_maksimka, 2014-10-19 13:39:51

How to count the number of rows with the same id in the database?

Hello
In the database there are rows with the same id, for example, the same customer ordered several products. How to count the number of customers who ordered more than 3 products? SQL language
+----+-------+--------+
| id | name | phone |
+----+-------+--------+
| 2 | name2 | phone1 |
| 2 | name2 | phone2 |
+----+-------+--------+

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-10-19
@begemot_sun

SELECT COUNT(*) AS c FROM table GROUP BY id HAVING c > 3

D
dmitriev_maksimka, 2014-10-19
@dmitriev_maksimka

41826e6e069547b9aaa0946a382f3fdd.PNG53c77e04826d46f7ba8decf9f5326c2d.PNG
Exact task - you need to display the names of customers who had more than 3 orders.
Database in SQLServer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question