SUM of grouped COUNT in SQL Query
SELECT name, COUNT(name) AS count
FROM table
GROUP BY name
UNION ALL
SELECT 'SUM' name, COUNT(name)
FROM table
OUTPUT:
name count
-------------------------------------------------- -----------
alpha 1
beta 3
Charlie 2
SUM 6
SUM of grouped COUNT and add proportion in SQL Query
Perhaps something like this
select
name,
count(1) cnt,
count(1) / (select count(1) from table1) proportion
from table1
group by name
Here's a SQLFiddle
SQL Count, Sum and Group by
Try this answer. This is very basic level Aggregate
functionality. Can you please search on the net, you'll get the answer easily:
SELECT MODEL
,COUNT(1) AS QTY
,SUM(COST) AS COST
FROM [Table] GROUP BY MODEL
SQL: Get SUM of grouped query having count statement
Use a subquery against your current query:
SELECT SUM(summe)
FROM
(
SELECT COUNT(adrnr) AS summe
FROM tablename
WHERE datum >= '2021-08-01' AND datum < '2021-09-01'
GROUP BY adrnr
HAVING COUNT(drnr) > 1
) t;
Note: Your timestamp/date literals looked a bit off. The above assumes you only want to target the month of August, 2021.
How to sum and count Id's grouped by date from joining Tables in SQL
UNION
your tables in a subquery and do aggregation and group by on top of that:
select count(1) as trans_count
,sum(amount_tendered) as amount_tendered
,DATE(transaction_datetime) as transaction_datetime
from
(select station_levy_id as trans, amount_tendered, transaction_datetime
from station_levy
union all
select market_levy_id as trans, amount_tendered, transaction_datetime
from market_levy) temp
group by DATE(transaction_datetime)
See result in SQL Fiddle
Related Topics
How to Get a List of Element Names from an Xml Value in SQL Server
Base 36 to Base 10 Conversion Using SQL Only
Multiple Array_Agg() Calls in a Single Query
Union All VS or Condition in SQL Server Query
Prepared Statement on Postgresql in Rails
Determine What User Created Objects in SQL Server
Getting Warning: Null Value Is Eliminated by an Aggregate or Other Set Operation
"Column Not Allowed Here" Error in Insert Statement
The Conversion of a Datetime2 Data Type to a Datetime Data Type Resulted in an Out-Of-Range
In SQL How to Get the Maximum Value for an Integer
Finding a Top Level Parent in SQL
Combinations (Not Permutations) from Cross Join in SQL
How to Search SQL Column Containing JSON Array
How to Implement SQL Intersect and Minus Operations in Ms Access
How to Use a Dynamic Parameter in a in Clause of a JPA Named Query