我想選擇使用下面的查詢條件乘法:SQL - 選擇多重條件
SELECT (SELECT count(*)
FROM users
)
as totalusers,
(SELECT sum(cashedout)
FROM users
) AS cashedout,
(SELECT COUNT(*)
FROM xeon_users_rented
) AS totalbots,
(SELECT sum(value)
FROM xeon_stats_clicks
WHERE typ='3' OR typ='1'
) AS totalclicks
上面的查詢只需要下一個第二(0.912確切)來執行。這會使成千上萬的請求減慢很多。
什麼似乎是合乎邏輯對我來說是這樣的方法:
SELECT (SELECT count(*), sum(cashedout)
FROM users
)
as totalusers, cashedout,
(SELECT COUNT(*)
FROM xeon_users_rented
) AS totalbots,
(SELECT sum(value)
FROM xeon_stats_clicks
WHERE typ='3' OR typ='1'
) AS totalclicks
但是不工作,我得到了以下錯誤:
#1241 - Operand should contain 1 column(s)
此外,我怎麼能加入其他兩個我的第一個查詢中的表「xeon_users_rented
」和「xeon_stats_clicks
」?
發表您的數據庫架構,原始數據的樣本和預期的結果 – Alex