Reputation: 623
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())
Upvotes: 2
Views: 2655
Reputation: 713
I think what you are looking for is UNION operation might help you.
Please take a look at this resource : W3SCHOOLS_UNION
Upvotes: 2
Reputation: 4192
Use UNION ALL method :
SELECT sum1 Sums
FROM your_tablename
UNION ALL
SELECT sum2 Sums
FROM your_tablename
Upvotes: 3