我尝试了以下查询,但我没有计算重复项 请帮帮我。
SELECT id
, Count(id) As theCount
FROM (
SELECT e.id
, e.cont
, e.date
, p.fname
, p.lname
, p.phone_cell
, p.phone_home
, p.email AS Count
FROM pdata AS p
, ehistory AS e
WHERE p.id = e.id
AND e.date >= '2007-08-05'
AND e.date <= '2019-08-10'
) As C
GROUP BY id
HAVING COUNT Count(id) > 1
;
我收到错误
在'Count(id)&gt;附近使用的语法1'
我认为一切都是正确的。如果有什么不对的帮助我!在此先感谢。
答案 0 :(得分:0)
您必须删除COUNT
单词,如下所示
SELECT id, Count(id) As theCount
FROM ( SELECT e.id, e.cont, e.date, p.fname, p.lname, p.phone_cell, p.phone_home, p.email AS Count
FROM pdata AS p, ehistory AS e
WHERE p.id = e.id
AND e.date >= '2007-08-05'
AND e.date <= '2019-08-10') As C
GROUP By id
HAVING Count(id) > 1
答案 1 :(得分:0)
您似乎两次使用'COUNT'
试试这个
HAVING COUNT(id) > 1
而不是
HAVING COUNT Count(id) > 1
答案 2 :(得分:0)
HAVING Count(id) > 1
答案 3 :(得分:0)
有2个计数。删除一个:
试试这个:
SELECT
id,
COUNT(id) AS theCount
FROM
(SELECT
e.id,
e.cont,
e.date,
p.fname,
p.lname,
p.phone_cell,
p.phone_home,
p.email AS COUNT
FROM
pdata AS p,
ehistory AS e
WHERE p.id = e.id
AND e.date >= '2007-08-05'
AND e.date <= '2019-08-10') AS C
GROUP BY id
HAVING COUNT (id) > 1 ;
答案 4 :(得分:0)
使用别名:::
SELECT id
, Count(id) As theCount
FROM (
SELECT e.id
, e.cont
, e.date
, p.fname
, p.lname
, p.phone_cell
, p.phone_home
, p.email AS Count
FROM pdata AS p
, ehistory AS e
WHERE p.id = e.id
AND e.date >= '2007-08-05'
AND e.date <= '2019-08-10'
) As C
GROUP BY id
HAVING theCount > 1
;
答案 5 :(得分:0)
尝试以下查询
SELECT Count(e.id) As theCount
, e.id
, e.cont
, e.date
, p.fname
, p.lname
, p.phone_cell
, p.phone_home
, p.email AS Count
FROM pdata AS p
, ehistory AS e
WHERE p.id = e.id
AND e.date between '2007-08-05' AND '2019-08-10'
GROUP BY e.id
HAVING theCount > 1;