0

当我在以下子查询中包含 2 条注释掉的行时,我的 Sybase 12.5 ASE 服务器似乎需要很长时间才能获得任何结果。没有这 2 行,查询运行正常。那个分组有什么问题?

select days_played.day_played, count(distinct days_played.user_id) as OLD_users
from days_played inner join days_received
on days_played.day_played = days_received.day_received
and days_played.user_id = days_received.user_id
where days_received.min_bulk_MT > days_played.min_MO
and days_played.user_id in

(select sgia.user_id 
from days_played as sgia
where sgia.day_played < days_played.day_played
--group by sgia.user_id 
--having sum(sgia.B_first_msg) = 0
)

group by days_played.day_played
4

3 回答 3

0

通过使用 showplan 来显示解释,找出查询的作用。

在这种情况下,您不能通过使子查询成为主查询的一部分来消除子查询吗?

于 2009-10-16T10:48:18.300 回答
0

您可以尝试如下重写查询吗?

select days_played.day_played,
       count(distinct days_played.user_id) as OLD_users
  from days_played
 inner join days_received on days_played.day_played = days_received.day_received
                         and days_played.user_id = days_received.user_id
 where days_received.min_bulk_MT > days_played.min_MO
   and 0 = (select sum(sgia.B_first_msg)
              from days_played as sgia
             where sgia.user_id = days_played.user_id
               and sgia.day_played < days_played.day_played
            )
 group by days_played.day_played

我想这应该会给你更好的表现......

于 2009-10-16T10:55:01.227 回答
0

好的,我发现问题是我必须在子查询中包含用户 ID:“其中 days_played.user_id = sgia.user_id 和 sgia.day_played < days_played.day_played”

于 2009-10-16T12:07:07.660 回答