1

这是我的第一个可以正常工作的查询。

SELECT count(event_log_id) as icount, cast(youth_name as varchar(max)) as yname
FROM CIRComplete
WHERE  actual_date between '2012-01-01' and '2012-04-30'
  AND is_deleted = '0' AND Closed = '1' 
GROUP BY cast(youth_name as varchar(max))

这将给我两列,icount 和 yname

我想执行第二个查询,它将给我 yname 和 icount 其中 icount > 1

我已经在这几个小时了,终于决定寻求帮助。

4

3 回答 3

1

为什么要进行第二次查询?这应该这样做:

SELECT
   count(event_log_id) as icount ,
   cast(youth_name as varchar(max)) as yname 
   FROM CIRComplete 
   WHERE (actual_date between '2012-01-01' and '2012-04-30') and 
         is_deleted = '0' and Closed = '1' 
   GROUP BY cast(youth_name as varchar(max))
   HAVING count(event_log_id) > 1
于 2012-05-22T17:17:13.397 回答
0
SELECT  cast(youth_name as varchar(max)) as yname,
        count(event_log_id) as icount
FROM    CIRComplete
WHERE   (actual_date between '2012-01-01' AND '2012-04-30') AND 
        is_deleted = '0' AND 
        Closed = '1' 
GROUP BY cast(youth_name as varchar(max))
HAVING  count(event_log_id) > 1
于 2012-05-22T17:17:54.037 回答
0
SELECT  
   count(event_log_id) as icount
  ,cast(youth_name as varchar(max)) as yname
FROM
  CIRComplete
WHERE 
   (actual_date between '2012-01-01' and '2012-04-30') and is_deleted = '0' and Closed = '1' 
GROUP BY
   cast(youth_name as varchar(max))
having icount > 1
于 2012-05-22T17:17:59.383 回答