0
以下のコードでは、MRR_CreatedとUNIONのMRR_Destroyedをどのように組み合わせて、次の数値のみを表示するのですか?今すぐクエリが正しいですが、別々に増減を見る必要はありません。選択サブクエリのUNIONの問題
select account.email, account.vip, datediff(now(), account.date_created) AS Age,
(select sum(account_subscription.next_invoice_price) as ActiveMRR
from account_subscription
where account_subscription.status = 'active'
and account_subscription.acctid = account.acctid
) as MRR,
(select count(account_subscription.subid) as Churn
from account_subscription
where account_subscription.date_created between DATE_ADD(NOW(), INTERVAL -2880 MINUTE) and NOW()
and account_subscription.date_closed between DATE_ADD(NOW(), INTERVAL -2880 MINUTE) and NOW()
and account_subscription.acctid = account.acctid
) as Churn,
(select sum(account_subscription.next_invoice_price) as MRR
from account_subscription
where date(account_subscription.date_created) = date(curdate())
and account_subscription.acctid = account.acctid
) as MRR_Created,
(select sum(account_subscription.next_invoice_price) as MRR
from account_subscription
where date(account_subscription.date_closed) = date(curdate())
and account_subscription.acctid = account.acctid
) as MRR_Destroyed,
concat("https://sitetest.com?ACCTID=",account.acctid) as URL
from account
where account.status = 'active'
and (
account.type in ('affiliate', 'customer', 'customer_freetrial', 'customer_duplicate', 'customer_match')
or account.type is null
)
group by account.acctid
order by MRR desc
ほとんどの奇妙な点は、作成した合計を正の数で表現しようとしていることです。合計は負の値で閉じてから、正味の変化を得るために合計します。 2つのクエリを使用してUNIONを使用しようとする考えでした – skyrunner
@skyrunner値が説明どおりに保存されている場合(正の値で開き、負の値で閉じた場合)、このクエリによってネットが得られます。または、すべての値が正の数として格納されていることを意味し、クエリ内でその分離を行う必要がありますか? –
残念ながら、すべてが肯定的に格納されています – skyrunner