简体   繁体   中英

SQL - Get all rows of table one and count of rows

How do I create an SQL query which gets all the rows of the table and count of rows inserted under e-mail?

I tried something like this, but this groups the rows and so I don't get all the rows.

SELECT *, COUNT(email) AS 'count' FROM adverts GROUP BY email
select a1.*, a2.count
from adverts a1
join
(
  SELECT email, COUNT(*) AS 'count' 
  FROM adverts 
  GROUP BY email
) a2 on a1.email = a2.email

try this,

select *,
    (select count(Email) 
    from adverts  where adverts.Email =a.Email) as EmailCount
    from adverts as a

or this

SELECT *, COUNT(email) OVER (PARTITION BY  email) as EmailCount FROM adverts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM