jenny sam
jenny sam

Reputation: 191

Sum two values after Union of same table

this is my query:

SELECT location_description as Crimes,COUNT(*)
FROM test_sample
where test_sample.day_of_week LIKE"%sunday"
GROUP BY test_sample.location_description
UNION ALL
SELECT location_description as Crimes,COUNT(*)
FROM test_sample
where test_sample.day_of_week LIKE"%saturday"
GROUP BY test_sample.location_description

My output is: enter image description here

How can i merge this two duplicate values into one.

Upvotes: 0

Views: 45

Answers (2)

Maksym Fedorov
Maksym Fedorov

Reputation: 6456

If you need get count of records only by 'location_description' field than you can use only grouping without union

SELECT location_description AS Crimes,
       COUNT(*)
FROM test_sample
WHERE day_of_week LIKE "%sunday"
  OR day_of_week LIKE "%saturday"
GROUP BY location_description

Upvotes: 3

jarlh
jarlh

Reputation: 44716

No need to UNION now, simply adjust WHERE to include both days;

SELECT location_description as Crimes,COUNT(*)
FROM test_sample
where test_sample.day_of_week LIKE"%sunday"
   or test_sample.day_of_week LIKE"%saturday"
GROUP BY test_sample.location_description

Upvotes: 3

Related Questions