-1

我尝试使用以下查询,但未能计算重复项,请帮帮我。

   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) > 1' 附近使用的语法

我认为一切都是正确的。如果有什么不对的,请帮帮我!提前致谢。

4

6 回答 6

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
于 2013-08-13T09:48:23.163 回答
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;
于 2013-08-13T10:17:50.857 回答
0

您正在使用两个 COUNT。改用这个

      HAVING Count(id) > 1
于 2013-08-13T09:51:15.177 回答
0

看来您使用了 'COUNT' 两次

尝试这个

HAVING COUNT(id) > 1

代替

HAVING COUNT Count(id) > 1
于 2013-08-13T09:50:34.987 回答
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 ;
于 2013-08-13T09:53:12.897 回答
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
       ;
于 2013-08-13T09:54:37.157 回答