Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:38:07+00:00 2026-06-11T06:38:07+00:00

I need to run a query which find a count of different categories. For

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:38:08+00:00Added an answer on June 11, 2026 at 6:38 am

    You could use case statements:

    SELECT BusNo, 
        SUM (CASE WHEN Route in (10,20,40) THEN 1 ELSE 0 END)) AS ShortRoute,
        SUM (CASE WHEN Route in (45,60,70) THEN 1 ELSE 0 END)) AS LongRoute
    FROM RoutesTable
    GROUP BY BusNo
    

    If the long/short route info is contained in another table, let’s say RouteInfo:

    SELECT BusNo, 
        SUM (CASE WHEN RouteInfo.Route = 'short' THEN 1 ELSE 0 END)) AS ShortRoute,
        SUM (CASE WHEN RouteInfo.Route = 'long' THEN 1 ELSE 0 END)) AS LongRoute
    FROM RoutesTable
        INNER JOIN RouteInfo ON RoutesTable.Route = RouteInfo.Route
    GROUP BY BusNo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to run an Oracle query which goes to insert
I need to run a SQL Query in vb.net to find the average rating
I need to run a query that returns a list of users, along with
I need to run a JOIN query on a solr index. I've got two
I want to run a sql query on a specific schedule (weekly) and need
Let's say I have an Oracle database table of 40MM 9-digit ZIP codes which
In SQL Server 7.0, I need to find out which users have write access
i need run code that will create a database and populate tables. i am
I need run ts:reindex when smth add in model or destroy from model. How
I need to run the application that I have made in Xcode on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.