3
這是我使用的顯示頁面的統計查詢:添加限制1至數查詢
$sql = "
SELECT SUM(num) as num FROM (
SELECT
COUNT(URL) AS num
, 'World' AS GoSection
, 'GW' AS MySite
FROM gw_geog
WHERE URL = :MyURL AND G1 = 1
UNION ALL
SELECT
COUNT(URL) AS num
, 'World' AS GoSection
, 'GW' AS MySite
FROM gw_geog_political
WHERE URL = :MyURL
) AS X";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':MyURL',$MyURL,PDO::PARAM_STR);
$stmt->execute();
$Total = $stmt->fetch();
我希望有兩個變化:
1)刪除WHERE URL =:MyURL從每一行,並通過添加LIMIT將其納入單個線在查詢
2)扎普重複的結束1
這就是我現在正在處理的內容。
$sql = "SELECT SUM(num) as num FROM (
SELECT COUNT(URL) AS num, 'World' AS GoSection, 'GW' AS MySite FROM gw_geog WHERE URL = :MyURL AND G1 = 1
UNION ALL
SELECT COUNT(URL) AS num, 'World' AS GoSection, 'GW' AS MySite FROM gw_geog_political WHERE URL = :MyURL
) AS X
WHERE X.URL LIKE :MyURL LIMIT 1";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':MyURL',$MyURL,PDO::PARAM_STR);
$stmt->execute();
$Total = $stmt->fetch();
但是,我得到錯誤信息未知列X.SUM(或X.URL等)。
有人可以告訴我正確的方法嗎?
你能澄清 「ZAP重複」?對我來說,這意味着它應該只統計一次每個獨特的URL,無論它在哪個表中存在,是嗎? –