查看重复记录和多个where子句错误

时间:2014-03-18 15:29:03

标签: mysql sql

我有一个问题,我正在寻找重复的用户ID并需要2个where子句。不幸的是,下面的查询给我一个错误。如何根据我想要的标准查看重复的用户ID?

select user_id, 
       order_placed, 
       downloaded, 
       template 
  from orders
GROUP BY 
       user_id, 
       order_placed, 
       downloaded, 
       template 
where (modified >= '2014-01-01' and downloaded = 'N' )
HAVING count(*) > 1

1 个答案:

答案 0 :(得分:0)

WHERE之后 GROUP BY之前放置FROM

SELECT user_id, 
       order_placed, 
       downloaded, 
       template,
       COUNT(*) 
  FROM orders
 WHERE (    modified  >= '2014-01-01' 
        and downloaded = 'N' )
GROUP BY 
       user_id, 
       order_placed, 
       downloaded, 
       template 
HAVING count(*) > 1;