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 7059223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:12:23+00:00 2026-05-28T04:12:23+00:00

I want to find AVG on same column by values in different column single

  • 0

I want to find AVG on same column by values in different column single sql query.

table - question_rating
review_id
question_id
rating
  • for each review there are multiple 16 questions and ratings.
  • question_id values are 1 to 16.
  • rating values are from 1 to 5.

I want to find avg of group of questions as

Desired output-

qustion_id     rating
-------------------------
g1               4.4
g2               3.7
g3               5.6

g1 is group of questions (1,3)
g2 is group of questions (2,6)
g3 is group of questions (7,8)
….g8

pseudo code-

 select (if(qustion=1 and question=3) as g1,
if(qustion=2 and question=6) as g2), ..
)avg(rating of respective group) from question_rating

I know it can be done by taking query separately but I want to know by single query.

Or any easy way to find such output by php,etc.

  • 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-28T04:12:24+00:00Added an answer on May 28, 2026 at 4:12 am

    You should make a table question_groups

    question_id  group_id
    q1          g1
    q2          g2
    q3          g1
    q4          g3
    q5          g3
    q6          g2
    

    And the select will be

    select group_id, avg(rating)
    from question_rating a
      join question_groups b on (a.question_id= b.question_id)
    group by group_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find an SQL query to find rows where field1 does not
I want to find a sql command or something that can do this where
I have a query where I want to replace avg(j2) with avg(case when j2
I want to find all instances in a table where a string field cannot
I have some scattered 3D points (2d solution is sufficient). I want find different
I want to find records on a combination of created_on >= some date AND
I want to find a way to develop database projects quickly in Visual Studio.
I want to find any text in a file that matches a regexp of
I want to find out all the subdomains of a given domain. I found
i want to find the mime-type for a given file extension on an IIS

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.