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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:11:06+00:00 2026-05-25T02:11:06+00:00

I have a query like : SELECT DISTINCT g.thumb, h.hotel_name, h.id, COUNT(c.id) as total_comments,

  • 0

I have a query like :

SELECT DISTINCT
g.thumb, h.hotel_name, h.id, COUNT(c.id) as total_comments, SUM(c.rating) AS total_ratings
FROM 
at_hotels h 
LEFT JOIN 
at_gallery g 
ON 
h.id = g.h_id
LEFT OUTER JOIN
at_comments c
ON
h.id = c.h_id AND c.status = '1'
GROUP BY h.id 
ORDER BY h.id DESC LIMIT 5

Query is working except SUM(rating). Sum command is giving more than expected. I also tried SUM command like this :

--query
(SELECT SUM(rating) FROM at_comments WHERE at_comments.h_id = at_hotels.id) AS total
--more query

and this is not worked too.

total must be : 13, but this is giving 36. Where is the problem?

Sample Data : (Comments Table)

id h_id rating
----------
1 | 1  |5
----------
2 | 1  |3
----------
3 | 1  |5

My Tables :

Tables

  • 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-25T02:11:07+00:00Added an answer on May 25, 2026 at 2:11 am

    I solved this problem.

    The problem was the ‘rating’ row DATA TYPE.

    Rating row datatype was ‘SET’ and the values 1,2,3,4,5.

    I changed data type to the TINYINT, records are automatically changed like this :

    5 -> 16
    3 -> 4
    5 -> 16
    
    16 + 4 + 16 = 36
    

    So, summing ‘SET’ data type is buggy or something?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a query like this one : SELECT DISTINCT `a`.*, `b`.*, `c`.* FROM
If I have a query like: SELECT DISTINCT unnest(test) AS test FROM table ORDER
Hello I have this query : SELECT DISTINCT a.id, a.runcd, (SELECT SUM(b.CALVAL) FROM GRS
In SQL Server 2000 I have a query like SELECT DISTINCT A.COLUMN1, B.COLUMN2 FROM
I have a select query like this select count(distinct id)*100/totalcount as freq, count (distinct
I have a query: select a.kli, b.term_desc, count(distinct(a.adic)) as count, a.partner_id from ad_delivery.sgmt_kli_adic a
I have a query like: SELECT ... FROM ... WHERE .. AND SomeID =

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.