Skip to content
Advertisement

SQL pivot count and sum 2 columns

I have a table

Query and I got count correct for column Times

Results correct count3 for shop1, count 2 for shop2

new query add column times2

Results and not count for column times2. Can we count and sum for both columns? Thank you.

Expect results

Advertisement

Answer

One option is a UNION ALL

Example

Returns

And Yet another option is change the count to a SUM()

Example

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement