如何创建一个SQL查询,该查询获取表格的所有行和在电子邮件下插入的行数?
我尝试过类似的东西,但这会对行进行分组,因此我无法获取所有行。
SELECT *, COUNT(email) AS 'count' FROM adverts GROUP BY email
答案 0 :(得分:2)
select a1.*, a2.count
from adverts a1
join
(
SELECT email, COUNT(*) AS 'count'
FROM adverts
GROUP BY email
) a2 on a1.email = a2.email
答案 1 :(得分:1)
试试这个,
select *,
(select count(Email)
from adverts where adverts.Email =a.Email) as EmailCount
from adverts as a
或者
SELECT *, COUNT(email) OVER (PARTITION BY email) as EmailCount FROM adverts