<?php
$result = mysql_query("SELECT COUNT(`uid`), `mac`, SUM(`time`)/60 AS ConnTime, SUM(`download`)/1000000 AS TotalDown, SUM(`upload`)/1000000 AS TotalUp
FROM `cdr_data_january`
WHERE (`towerid` LIKE '".$btsid."') AND (`ldate` BETWEEN '".$date1."' AND '".$date2."')
GROUP BY `uid`
UNION
SELECT COUNT(`uid`), `mac_add`, SUM(`time`)/60 AS ConnTime, SUM(`download`)/1000000 AS TotalDown, SUM(`upload`)/1000000 AS TotalUp
FROM `cdr_data_february`
WHERE (`bts` LIKE '".$btsid."') AND (`ldate` BETWEEN '".$date1."' AND '".$date2."')
GROUP BY `uid`");
mysql_fetch_row($result);
$numrows = mysql_num_rows($result);
?>
编辑这里是为了可读性而格式化的 sql。
SELECT COUNT(`uid`),
`mac`,
SUM(`time`)/60 AS ConnTime,
SUM(`download`)/1000000 AS TotalDown, SUM(`upload`)/1000000 AS TotalUp
FROM `cdr_data_january`
WHERE (`towerid` LIKE '".$btsid."')
AND (`ldate` BETWEEN '".$date1."' AND '".$date2."')
GROUP BY `uid`
UNION
SELECT COUNT(`uid`),
`mac_add`,
SUM(`time`)/60 AS ConnTime,
SUM(`download`)/1000000 AS TotalDown,
SUM(`upload`)/1000000 AS TotalUp
FROM `cdr_data_february`
WHERE (`bts` LIKE '".$btsid."')
AND (`ldate` BETWEEN '".$date1."' AND '".$date2."')
GROUP BY `uid`
上面的行没有返回我的行数。
上面的代码在我用 (*) 抓取整个表格并像 COUNT(*) 一样计数时有效。
请给我一个解决方案,以便我可以获得使用多个 UNION 并且不抓取所有列的此类查询的行数。