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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:21:51+00:00 2026-06-04T20:21:51+00:00

Right now I have 3 tables, the first one for users, the second for

  • 0

Right now I have 3 tables, the first one for users, the second for group of users and the third one for points (and other ones, if you want one I could create it for you :P).

Table users:

user_id
|
fname
|
active

Table user_groups:

id
|
group_id
|
user_id
|
active

Table user_points:

id
|
point_type
|
point_units
|
active

Each user of a group could earn points for different activities. So, I want to show the points that the users have earned for their different activities, with a grand total at the end.

Here’s the query that I have so far:

SELECT 
    u.user_id AS `ID`,  
    u.fname AS `Name`,  
    SUM(case when up.point_type = 'Referrals' then up.point_units else 0 end) AS `Referrals`, 
    SUM(case when up.point_type = 'Email' then up.point_units else 0 end) AS `Email`, 
    SUM(case when up.point_type = 'Facebook' then up.point_units else 0 end) AS `Facebook`, 
    SUM(case when up.point_type = 'Twitter' then up.point_units else 0 end) AS `Twitter`, 
    SUM(case when up.point_type = 'Extra' then up.point_units else 0 end) AS `Extra`, 
    SUM(case when up.point_type = 'Discount' then up.point_units else 0 end) AS `Discount`, 
    SUM(case when u.user_id = up.user_id then up.point_units else 0 end) AS `Total` 
FROM users AS u, user_groups AS uc, user_points AS up 
WHERE u.user_id = uc.user_id 
    AND u.user_id = up.user_id 
    AND u.active = 1 
    AND uc.active = 1 
    AND up.active = 1 
    AND uc.group_id = up.group_id 
    AND uc.group_id = 65 
ORDER BY u.fname; 

The problem that I have is that the query only shows one user and the total sum of the points of all the users in each column.

I know that this isn’t the right approach, but I don’t know how to put everything into a query. Also, I’m giving this query to PHPExcel, so it could generate a nice friendly report.

Any ideas? 🙂

  • 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-04T20:21:53+00:00Added an answer on June 4, 2026 at 8:21 pm

    You need a GROUP BY clause when using aggregate functions. Yours might look like:

    GROUP BY u.user_id
    

    In your query it would go here:

    AND uc.group_id = 65 
    GROUP BY u.user_id
    ORDER BY u.fname;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now we have AD/Exchange to manage all of our users logins/e-mail on-site at
I have 2 tableViews, the first one is the Main table and the second
Thank you for looking at my issue. Right now I have 3 tables: tblEmployee
I am writing a MVC3 project. Right now I have a table which has
I am writing a MVC3 project. Right now I have a table which has
Good day! I right now have a function the drags an element from a
Right now I have this SQL query which is valid but always times out:
Right now I have def min(array,starting,ending) minimum = starting for i in starting+1 ..ending
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that

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.