Skip to content
Advertisement

Add count() to pivot table with totals

I have the following query: (simplified to one year)

–and the PIVOT

For it I’m trying to add the count of orders for each year, but I’m having problems understanding how should I proceed, I might be complicating it too much, but I’m not getting the proper count I think that the myTable table is getting properly the “countOrders” but I’m not sure if I’m doing it properly on the pivot table to group by them and show the count by year

right now it kinda seems that is counting all the orders as I needed, however when I manually check on the DB seems that the data is off.

also, something I don’t understand is why is it repeating the “company” so many times when I’m doing grouping by it?

example

Advertisement

Answer

I ended up case instead of pivot table. this solved the issue, with format:

in case it works for someone 🙂

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