I need to run a query which find a count of different categories. For example:
Let’s say, route No: 10,20,40 are categorized under “Short-routes” and route No: “45,60 and 70” are categorized under “Long-routes”. Different buses ply over one or more of these routes.
Example: (A, B, C are bus Nos)
Bus No. Route
- A 10
- A 45
- B 40
- B 45
- B 60
- A 20
- C 70
I am trying to write a sql query which would return the count of categories each bus ply or does not ply to (indicated by a count of zero for that category):
That is:
- Bus NO. Short Route Long Route
- A 2 1
- B 1 2
- C 0 1
The information that C does not ply (0 count) on a short route is imperative. How can I get my query to return me the result as above?
Thank you!
You could use case statements:
If the long/short route info is contained in another table, let’s say
RouteInfo: