1
<?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が使用され、すべての列が取得されていないようなクエリの行数を取得できるように解決策を教えてください。

4

1 に答える 1