0
我有三個查詢都返回1行和1列。我想將它作爲1行和3列返回。將三個查詢合併爲單個結果
我的查詢
select count(distinct rt) from gpstable where rt > GETDATE() - '1 day'::INTERVAL AND di like 'i';
select count(distinct rt) as count from gpstable where rt > GETDATE() - '1 day'::INTERVAL group by di order by count limit 1;
select count(distinct rt) as count from gpstable where rt > GETDATE() - '1 day'::INTERVAL group by di order by count DESC limit 1;
這是我曾嘗試
select userCount, min, max
from
(select count(distinct rt) as userCount from gpstablev2 where rt > GETDATE() - '1 day'::INTERVAL AND di like 'UmTqUo1MQU8FgXfXXGNFh7vZnQN+bt2ThIQIDHNnmWU=') as userCount,
(select count(distinct rt) as min from gpstablev2 where rt > GETDATE() - '1 day'::INTERVAL group by di order by count limit 1) as min,
(select count(distinct rt) as max from gpstablev2 where rt > GETDATE() - '1 day'::INTERVAL group by di order by count DESC limit 1) as max;
而且我得到以下錯誤錯誤:列 「計數」 不gpstablev2存在[SQL狀態= 42703]
所以我不知道爲什麼,也許是因爲我使用AWS Redshift和只是一個PSQL數據庫。但是你的「current_date - interval '1'一天'導致執行時間增加到約15secs,其中「GETDATE() - '1天':: INTERVAL」保持執行時間低於1秒。不確定是否有某種緩存正在進行... –
@ djc391:謝謝你的反饋,這是真的很奇怪,我從來沒有使用「普通」Postgres版本觀察到這種差異。那麼'current_date - 1'呢? –