In my project I'm trying to write a query to fetch data for a stacked bar graph. Instead of explaining the schema of my DB (which would be lengthy), I found a similar analogy which I can port to my DB later.
On this page, run the query
SELECT * FROM [Products]
In the table, if I want to select data for stacked bar graph as below, how do I form the query?
Sorry, I'm not able to demonstrate substantial research effort in this, as I'm not even able to visualize what the SELECT clause would look like. I tried to check if we can use AS in WHERE clause and then do a COUNT on it. But that does not seem to be correct syntax.
I'm going to be running the actual query on MS SQL Server through PowerBI
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
*
FROM
[Products]