2

I have run a SUM query to achieve the following 2 columns and rows:

sum1 | sum2
10     20

The query I ran was the following:

SELECT SUM(minutes) as "sum1", SUM(hoursWorked) AS "sum2"
FROM  entries
JOIN  employees on employeeID = employees.userID 
WHERE YEARWEEK(dateCreated) = YEARWEEK(NOW()) 
ORDER BY employeeID;

I want to combine the values into one column, to get the following:

sums
10
20

A bit lost on how to start with this. Searching has resulting in Concat which obviously wont work.

Can anyone help suggest a method to do this, or the correct function I should be searching for?

EDIT: As suggestions below, I resolved this by doing the following:

SELECT SUM(minutes) as "sum1"
FROM   entries
JOIN   employees on employeeID = employees.userID 
WHERE  YEARWEEK(dateCreated) = YEARWEEK(NOW())
UNION
SELECT SUM(hoursWorked) AS "sum2"
FROM   entries
JOIN   employees on employeeID = employees.userID 
WHERE  YEARWEEK(dateCreated) = YEARWEEK(NOW()) 

2 Answers 2

3

Use UNION ALL method :

SELECT sum1 Sums 
FROM your_tablename   
UNION ALL
SELECT sum2 Sums
FROM your_tablename    
Sign up to request clarification or add additional context in comments.

3 Comments

thanks! I have already run a query to return sum1 and sum2, from two tables. Can I use UNION ALL in the same query?
@JimDover,Yes it is possible UNION ALL in query.which table contain minutes & which table contain hoursWorked
Thanks!!! I resolved this - I edited my post with the solution also. Thank you for your help!
2

I think what you are looking for is UNION operation might help you.

Please take a look at this resource : W3SCHOOLS_UNION

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.