pricing
表pricing_type
上的永远不会为空
但是出于某种原因,当我加入那些表时,price
行总是为空:
SELECT DATE_ADD(`log`.`logtime`, INTERVAL 0 HOUR) AS `logtime`,
`log`.`called_number` AS `called_number`,
`pricing`.`pricing_type` AS `price`
FROM
(SELECT `id`, `logtime`, `called_number`,`affiliate_id` FROM `pbxlog` AS `log` WHERE (`log`.`src_number_blacklisted`=0 AND `log`.`logtime` >= DATE_SUB('2013-5-01', INTERVAL 0 HOUR) AND `log`.`logtime` < DATE_ADD(DATE_SUB('2013-5-25', INTERVAL 0 HOUR), INTERVAL 1 DAY)) AND ((`log`.`called_number` >= '449017988309' AND `log`.`called_number` <= '449017988309') OR (`log`.`called_number` >= '449017988317' AND `log`.`called_number` <= '449017988317') OR (`log`.`called_number` >= '449017988341' AND `log`.`called_number` <= '449017988341') OR (`log`.`called_number` >= '449017988343' AND `log`.`called_number` <= '449017988343') OR (`log`.`called_number` >= '449017988352' AND `log`.`called_number` <= '449017988352') OR (`log`.`called_number` >= '449017988354' AND `log`.`called_number` <= '449017988354') OR (`log`.`called_number` >= '449017988355' AND `log`.`called_number` <= '449017988355') OR (`log`.`called_number` >= '449017988368' AND `log`.`called_number` <= '449017988368') OR (`log`.`called_number` >= '449017988379' AND `log`.`called_number` <= '449017988379') OR (`log`.`called_number` >= '449017988381' AND `log`.`called_number` <= '449017988381') OR (`log`.`called_number` >= '449017988382' AND `log`.`called_number` <= '449017988382') OR (`log`.`called_number` >= '449017988383' AND `log`.`called_number` <= '449017988383') OR (`log`.`called_number` >= '449017988384' AND `log`.`called_number` <= '449017988384') OR (`log`.`called_number` >= '449017988401 ' AND `log`.`called_number` <= '449017988401 ') OR (`log`.`called_number` >= '449017988402' AND `log`.`called_number` <= '449017988402') OR (`log`.`called_number` >= '449017988407' AND `log`.`called_number` <= '449017988407') OR (`log`.`called_number` >= '449017988470' AND `log`.`called_number` <= '449017988470') OR (`log`.`called_number` >= '449017988531' AND `log`.`called_number` <= '449017988531') OR (`log`.`called_number` >= '449017988532' AND `log`.`called_number` <= '449017988532') OR (`log`.`called_number` >= '449017988533' AND `log`.`called_number` <= '449017988533') OR (`log`.`called_number` >= '449017988534' AND `log`.`called_number` <= '449017988534') OR (`log`.`called_number` >= '449017988556' AND `log`.`called_number` <= '449017988556') OR (`log`.`called_number` >= '449017988716' AND `log`.`called_number` <= '449017988716') OR (`log`.`called_number` >= '449017988755' AND `log`.`called_number` <= '449017988755') OR (`log`.`called_number` >= '449017988765' AND `log`.`called_number` <= '449017988765') OR (`log`.`called_number` >= '449017988774' AND `log`.`called_number` <= '449017988774') OR (`log`.`called_number` >= '449017988775' AND `log`.`called_number` <= '449017988775') OR (`log`.`called_number` >= '449017988788' AND `log`.`called_number` <= '449017988788') OR (`log`.`called_number` >= '449017988796 ' AND `log`.`called_number` <= '449017988796 ') OR (`log`.`called_number` >= '449017988798 ' AND `log`.`called_number` <= '449017988798 ') OR (`log`.`called_number` >= '449017988801' AND `log`.`called_number` <= '449017988801') OR (`log`.`called_number` >= '449017988834' AND `log`.`called_number` <= '449017988834') OR (`log`.`called_number` >= '449017988877' AND `log`.`called_number` <= '449017988877') OR (`log`.`called_number` >= '449017988918' AND `log`.`called_number` <= '449017988918') OR (`log`.`called_number` >= '449017988970 ' AND `log`.`called_number` <= '449017988970 ') OR (`log`.`called_number` >= '449017988994' AND `log`.`called_number` <= '449017988994') OR (`log`.`called_number` >= '449017988996' AND `log`.`called_number` <= '449017988996')) LIMIT 10000) AS `log`
INNER JOIN
`pbxlog_phase` AS `phase` ON (`phase`.`call`=`log`.`id` AND `phase`.`src_type`='url' AND `phase`.`totaltime` >= 30)
LEFT JOIN
`affiliate_pricing` AS `pricing` ON (`log`.`affiliate_id` = `pricing`.`affiliate`)
答案 0 :(得分:0)
您在LEFT JOIN
和log
上使用affiliate_pricing
。这意味着即使log
中没有行,匹配affiliate_pricing
子句中的行,也会从ON
中选择所有行。由于affiliate_pricing
中没有可以与log
结合的行,因此会为affiliate_pricing
中的每一列选择空值。