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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:43:29+00:00 2026-05-31T07:43:29+00:00

I have a Reward System based on MySQL/PHP. Teachers award students points; students can

  • 0

I have a Reward System based on MySQL/PHP. Teachers award students points; students can then purchase rewards using their accrued points.

What I’d like to do is display a single percentage figure of students who have purchased rewards.

This sounds quite simple, but in practice it may be a little bit more complicated to achieve.

  • I don’t have a list of students in the database, I simply have transactions
  • If a student has received a point, their ID will be displayed in the transactions table under the Recipient_ID column

The transactions table looks like: Transaction_ID, Datetime, Giver_ID, Recipient_ID, Points, Category_ID, Reason.

The purchases table looks like: Purchase_ID, Datetime, Reward_ID, Quantity, Student_ID, Student_Name (blank), Date_DealtWith, Date_Collected

So, for example, I can list all of my student IDs using SELECT DISTINCT Recipient_ID
FROM transactions
.

All I basically need is:

  • [students] A count of students with a point+ (i.e. Recipient_ID in transactions)
  • [purchases] A count of students with a purchase+ (i.e. Student_ID in `purchases)
  • [purchases] / [students] * 100

.. but I’m not sure how to do that in one query!


EDIT: Insert Statements*

purchases…

INSERT INTO `purchases` (`Purchase_ID`, `Datetime`, `Reward_ID`, `Quantity`, `Student_ID`, `Student_Name`, `Date_DealtWith`, `Date_Collected`) VALUES
(1, '2011-09-27 16:55:16', 1, 1, 34240, '', '2011-09-27 16:55:16', '2011-12-12 15:45:43'),
(2, '2011-09-28 13:02:26', 1, 1, 137636, '', '2011-09-27 16:55:16', '2011-09-27 16:55:16'),
(3, '2011-09-29 11:29:09', 1, 1, 137685, '', NULL, NULL);

transactions…

INSERT INTO `transactions` (`Transaction_ID`, `Datetime`, `Giver_ID`, `Recipient_ID`, `Points`, `Category_ID`, `Reason`) VALUES
(1, '2011-09-07', 36754, 34401, 5, 6, 'Gave excellent feedback on the new student notebook'),
(2, '2011-09-07', 34972, 137615, 10, 9, 'Helping TG'),
(6, '2011-09-07', 35006, 90185, 2, 1, '');
  • 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-31T07:43:30+00:00Added an answer on May 31, 2026 at 7:43 am

    Here’s an ugly version, which manages to avoid doing the count of students from transactions twice through a hackish join between 2 sub-queries.

    SELECT
     numrewards_students,
     numpurchase_students,
     numpurchase_students / numrewards_students * 100.0
    FROM
     ( SELECT 0 AS joiner, COUNT( DISTINCT Recipient_ID ) AS numrewards_students FROM transactions ) AS trs
    JOIN ( SELECT 0 AS joiner, COUNT( DISTINCT Student_ID ) AS numpurchase_students FROM purchases ) AS prs ON trs.joiner = prs.joiner
    

    Another version, I’m not certain will work without a FROM clause in the sub-query – I can’t remember if MySQL will permit this:

    SELECT 
      numrewards_students,
      numpurchase_students,
      numpurchase_students / numreward_students * 100.0
    FROM 
    (
      (SELECT COUNT(DISTINCT) Recpipient_ID AS numrewards_students FROM transactions) AS numrewards_stduents,
      (SELECT COUNT(DISTINCT) Student_ID  AS numpurchases_students FROM purchases) AS numpurchase_stduents
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables in my Reward System's database: purchases => Purchase_ID ,
I am making a registration/login system with php. I think I have all the
So I have a members website written in PHP and MYSQL. Say for a
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Basically what I have is a system where users get rewarded for every 10
I have a dated system perl 5.8.8 on a Linux machine and installed a
I have an engineering firm and our website was built using Visual Studio 2010
I run a music website for amateur musicians where we have a rating system

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.