How can I join two tables in SQL and use function SUM on one column and show two other columns?

James

num (Table1) and id (Table2) contain the same information, so I can join them. I can add the sum using a function in the select statement. However, I need help adding the "location" column to my output, which comes from Table2.

How do I take the sum of all the departments for each id, and also add a location column to the output?

What I'm looking to do:

Example tables and output

What I have so far:

Select num, sum(amt)
From Table1
Inner join Table2 On id = num
Group by num
Ibrahim Hamaty

Like this:

Select num, location, sum(amt)
From Table1
Inner join Table2 ON id = num
Group by num, location

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can i join two tables with two columns that refers the same column in the second table in SQL Server

SQL - How can I JOIN two tables and SUM a column based on IDs between them?

How can I print in one column the SUM of two columns

How can I join one tables row as other tables column to use as dynamic values?

How can I SUM two tables with a join without duplicate data?

How can I show one element from one of two tables in a column

How do I join two tables in SQL to grab the names from one table and show them in a query?

Postgres: How Can I Make a JOIN/Junction Table Which References *One Of* Two Other Tables?

SQL JOIN and ORDER two tables by one column

How can I create a new column of values based on the grouped sum of values from two other columns?

What R function can I use to sum two columns and save the new variable as a new column?

How can I perform a left join comparing two months columns and getting the one right after the other?

Merge two columns from two tables in one SQL query and use value in tables as column name

How to show one column value in two columns in SQL Server

Show One Column Data as Two Columns in SQL

How to join two tables by multiple columns in SQL?

R_How can I fill blanks in one column with mean of two other columns?

How can I join two tables apropreately in (My)SQL?

How can I join two tables on an ID and a DATE RANGE in SQL

How can I merge rows and columns from two sql tables into one table

Join two tables and show Columns of one table as Rows

Inner Join for 3 tables with SUM of two columns in SQL Query?

How to name two columns in join tables with two same foreign key at one table in SQL?

Sum two tables value and show value if one column is null

How can I use SQL to find a record that is not in a table based on info from two other tables?

How to Join two tables and sum their columns across in Mysql based on distinct column

How can I stack one column on top of other two in bootstrap?

How do I join two tables and then select two different columns?

How can I join two tables with REALM