Add total of multiple counted columns

Lukas Østergaard

So I have a database where I have managed to count the number of IDs for each column and given them a easier to see name. using the query:

SELECT 
COUNT( Club_Id ) AS Club_membership, 
COUNT( Founder_Id ) AS Clubs_ounded, 
COUNT( Host_Id ) AS events_Hosted, 
COUNT( Attendee_Id ) AS attended, 
person_Id
FROM Social_Points
GROUP BY person_Id

output:

Club_membership | Clubs_founded  | events_hosted  | attended | person_ID  |
----------------+----------------+----------------+----------+------------+
          0     |          1     |          1     |    20    |     111    |
          2     |          0     |          0     |    16    |     222    |
          1     |          0     |          1     |    3     |     333    |
          3     |          0     |          0     |    20    |     444    |

I would like to have a column after "person_ID" that sums up the four other column Like this:

Club_membership | Clubs_founded  | events_hosted  | attended | person_ID  |  total  |
----------------+----------------+----------------+----------+------------+---------+
          0     |          1     |          1     |    20    |     111    |   22    |
          2     |          0     |          0     |    16    |     222    |   18    |
          1     |          0     |          1     |    3     |     333    |   5     |
          3     |          0     |          0     |    20    |     444    |   23    |

Is this possible? Or should I just call it a loss and write another solution in my report?

Manu Konomi

You could do something like this, although it is not pretty

SELECT 
COUNT( Club_Id ) AS Club_membership, 
COUNT( Founder_Id ) AS Clubs_ounded, 
COUNT( Host_Id ) AS events_Hosted, 
COUNT( Attendee_Id ) AS attended, 
person_Id,
COUNT( Club_Id ) + COUNT( Founder_Id ) + COUNT( Host_Id ) + COUNT( Attendee_Id ) as total
FROM Social_Points
GROUP BY person_Id

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Running total on multiple columns

Add quantiles to dataframe as multiple columns

How to add multiple columns to a DataFrame?

add multiple columns to pandas dataframe

calculate percentage of total for multiple columns

Pandas: best way to add a total row that calculates the sum of specific (multiple) columns while preserving the data type

How can I get a record to be counted in multiple columns of a Crosstab Query?

Single grand total ROLLUP with multiple columns

OVER and partition with multiple columns without resetting the total

sum same condition in multiple columns to get a total

Arrayformula Running Total with multiple columns

How to add multiple columns with purrr?

Running Total Referencing Multiple Columns Using Pandas

add multiple columns to an xts object

Add columns together for total value

Add price columns in a text file to show total

LINQ to Entities search multiple columns, order by total weight of the matches columns

Add multiple columns and rows to a table

Add Total Row For Columns D - M

How do you count occurrences in multiple columns and order results by calculation of counted columns in MySQL?

How to get the total sum of counted values separated by commas in multiple rows, but disregarding zeroes?

MySQL Sum total using Group By multiple columns

sql get total of value across multiple columns

pandas add multiple columns with apply

Create running total with multiple columns in Python

Total of multiple columns using datatables footer callback

How to get total size of specific counted extensions

R total multiple columns at once with n()

Rename the add_columns columns in modelsummary and add multiple columns

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive