current position:Home>The number of occurrences of certain fields in SQL query

The number of occurrences of certain fields in SQL query

2022-02-02 20:51:39 CSDN Q & A

id
1
1
2
3
4
4
5
6

For example, the watch is like this

Expect query results
id count
1 2
2 1
3 1

Just want to 1 2 3 The number of times they appear separately




Refer to the answer 1:

SELECT
id,
count(id)
FROM
indicate
GROUP BY
id




Refer to the answer 2:



Refer to the answer 3:
select id, count(*) as cnt from tb group by id



Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022051375818.html

Random recommended