我有这两个问题,我正在运行。第一个函数可以工作,但出于某种原因,它似乎增加了大约一分钟的加载时间,这使得它无法使用。所以我写了第二个问题,我觉得应该给出同样的答案,但它给出了一个非常不同的答案。
First
select
count(`FavoritesHeaderID`) `count`
from `favoritesheader`
join `vwactiveevent` on `vwactiveevent`.`MainEventID`=`favoritesheader`.`MainEventID`
where `Admin`=0
and exists(
select 1
from `invoiceheader`
join `vwactiveevent` on `vwactiveevent`.`MainEventID`=`invoiceheader`.`MainEventID`
where `Phone`=`favoritesheader`.`CellPhone`
and `OrderStatusID`=2
); => 284第二
select
count(`FavoritesHeaderID`) `count`
from `favoritesheader`
join `vwactiveevent` on `vwactiveevent`.`MainEventID`=`favoritesheader`.`MainEventID`
join `invoiceheader` on `vwactiveevent`.`MainEventID`=`invoiceheader`.`MainEventID`
where `Admin`=0
and `Phone`=`favoritesheader`.`CellPhone`
and `OrderStatusID`=2; => 1578我不知道这是不是足够的信息,但如果是,如果是,任何帮助将是非常感谢的。
发布于 2013-06-05 18:47:46
JOIN很可能在COUNT中包含重复行。如果我正确地理解了您的问题,假设FavoritesHeaderID是唯一的,并且这是您要COUNT的字段,您可以将DISTINCT添加到每个查询中,它们应该返回相同的计数:
select
count(distinct `FavoritesHeaderID`) `count`
from `favoritesheader`
join `vwactiveevent` on `vwactiveevent`.`MainEventID`=`favoritesheader`.`MainEventID`
join `invoiceheader` on `vwactiveevent`.`MainEventID`=`invoiceheader`.`MainEventID`
where `Admin`=0
and `Phone`=`favoritesheader`.`CellPhone`
and `OrderStatusID`=2https://stackoverflow.com/questions/16947377
复制相似问题