🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.databases.mysql
Article #1

Regd Merging These 2 MySql Queries into 1

#1
From: Paaro
Date: Sat, 09 Apr 2022 13:45
18 lines
1956 bytes
I have following two SQL queries to execute in mySQL.

SELECT total(amount) as total_receipts FROM receipts WHERE torderid = 101
SELECT total(amount) as total_refunds FROM refunds WHERE torderid = 101

I get following below values using these two above queries

total_receipts
total_refunds

Now I need to calculate net_receipts as below.

net_receipts = total_receipts - total_refunds


Is there way to get total_receipts, total_refunds and net_receipts by merging the above two queries into a single SQL query?

Please help.
Technical Details
Message-ID: <055e7e35-fe32-45a8-9ba4-1925bf628717n@googlegroups.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!news.usenet.blueworldhosting.com!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!feeder1.feed.usenet.farm!feed.usenet.farm!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <055e7e35-fe32-45a8-9ba4-1925bf628717n@googlegroups.com>
Subject: Regd Merging These 2 MySql Queries into 1
Date: Sat, 09 Apr 2022 13:45:56 +0000
From: Paaro <paaroonline@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!news.usenet.blueworldhosting.com!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!feeder1.feed.usenet.farm!feed.usenet.farm!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
X-Received: by 2002:a37:9442:0:b0:699:fd32:bc7d with SMTP id w63-20020a379442000000b00699fd32bc7dmr9044961qkd.615.1649511956709;
X-Received: by 2002:a05:622a:15c7:b0:2eb:9af4:cdf4 with SMTP id
 d7-20020a05622a15c700b002eb9af4cdf4mr19477959qty.241.1649511956563; Sat, 09
Newsgroups: alt.comp.databases.mysql
Injection-Info: google-groups.googlegroups.com; posting-host=49.205.132.240; posting-account=W3OKGwkAAABCaMQvOgyn4Mgom1Z7jy7b
NNTP-Posting-Host: 49.205.132.240
User-Agent: G2/1.0
MIME-Version: 1.0
Injection-Date: Sat, 09 Apr 2022 13:45:56 +0000
Content-Type: text/plain; charset="UTF-8"