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

  • Home
  • SEARCH
  • 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 1868298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:39:59+00:00 2026-05-17T06:39:59+00:00

I have a view which contains (among other columns) a header name, and an

  • 0

I have a view which contains (among other columns) a header “name”, and an item “rating” column. The view joins the header to the item table, so the name column from the header is repeated for every item.

I need to run a report on the table; ideally, I would have 5 columns in the sql result; the header “name”, and 4 copies of the “rating” column, where every copy of the rating column shows the count of ratings which are over a certain threshold. So rating column #1 will show the number of items in the table (for the item’s header) which have a rating of 1 or higher, the second rating column will show the number of items in the table (for the same item’s header) which have a rating of 5 or higher, and so on.

I know how to get the name and 1 rating column back:

select name, count(rating) as cnt1 from myview where rating > 1 group by name

but combining that with the other desired rating columns is failing me at the moment. Tried using a “union” clause, but that just puts multiple rows in the result list. An absolute requirement (the query has to plug into a report template, so this is very inflexible) is that I only have one row returned for every unique “name” field in the view, because otherwise the report object which is going to read the data won’t know how to interpret the results.

Any tips?

Update
Here is some sample data:

name, rating
myname1, 1
myname1, 1
myname1, 10
myname1, 4
myname1, 7
myname1, 3
myname1, 5
myname1, 5
myname1, 4
myname2, 2
myname2, 10
myname2, 6
myname2, 8
myname2, 5
myname2, 4
myname2, 6

And the desired output:

name, cnt1, cnt5, cnt7, cnt8
myname1, 7, 2, 1, 1
myname2, 7, 4, 2, 1

…where cnt1 = rating > 1, cnt5 = rating > 5, cnt7 = rating > 7, cnt8 = rating > 8

  • 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-05-17T06:39:59+00:00Added an answer on May 17, 2026 at 6:39 am
    select name,
           sum(case when rating > 1 then 1 else 0 end) as cnt1,
           sum(case when rating > 5 then 1 else 0 end) as cnt2
           /* ... repeat as many times as needed */
        from myview
        group by name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains procedure codes among other data (let's call it
I have a root view which contains a table and a button. When I
I have a header view which contains 4 buttons. When I click each of
I have a complex view model which contains a collection of other objects which
I have a ListView which contains EMPLOYEE_NAME from a DB table EMPLOYEE. Some employees
I have a view which contains a form, the form posts and the data
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach
I have a list view control which at the moment only allows one item
I have an image in a view which contains a 9x9 grid. I want
Suppose (for the sake of argument) that I have a view class which contains

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.