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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:48:47+00:00 2026-05-16T03:48:47+00:00

I am using some MySQL tables. Their structures are listed below. login: loginid username

  • 0

I am using some MySQL tables. Their structures are listed below.

“login”:

loginid username password email actcode disabled activated created points website location age gender

Each user has a loginid

“submission”:

submissionid loginid title slug url displayurl datesubmitted

In the submission table above, the “loginid” is the loginid of the user that submitted the submission.

“comment”:

commentid loginid submissionid comment datecommented

In the comment table above, “loginid” is the loginid of the user who made the comment. “submissionid” is the submission on which the comment was made.

The query below ranks the top 25 loginids by (days the loginid has been in existence) + (total submissions by the loginid) * 10 + (comments by the loginid).

I would like to include one more factor: (total comments made on submissionids that the loginid has submitted) * 10.

It would require the following:

  1. Getting all submissionids in the table “submission” for a given loginid
  2. Summing the total number of entries in the table “comment” that have those submissionids

How can I do this?

Thanks in advance,

John

$sqlStr2 = "SELECT 
    l.loginid, 
    l.username, 
    l.created,
    DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2
FROM login l    
LEFT JOIN (
    SELECT loginid, COUNT(1) AS total 
    FROM submission 
    GROUP BY loginid
) s ON l.loginid = s.loginid
LEFT JOIN (
    SELECT loginid, COUNT(1) AS total 
    FROM comment 
    GROUP BY loginid
) c ON l.loginid = c.loginid
GROUP BY l.loginid
ORDER BY totalScore2 DESC 
LIMIT 25";
  • 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-16T03:48:48+00:00Added an answer on May 16, 2026 at 3:48 am

    Introduce the below into your query as an additional join and then include the total * 10 into your totalscore2 calculation.

    LEFT JOIN (
        SELECT S2.loginid, COUNT(1) AS total 
        FROM submission S2
        INNER JOIN comment C2
        ON C2.submissionid = S2.submissionid
        GROUP BY S2.loginid
    ) scs ON scs.loginid = l.loginid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I have some mysql tables that are currently using an md5 hash as
I created some tables using MySQL Workbench, and then did forward ‘forward engineer’ to
I'm using MySQL 4.1. Some tables have duplicates entries that go against the constraints.
I'm trying to convert some mysql tables from latin1 to utf8. I'm using the
I'm using Codeigniter to insert some data into a MySQL table. However, the single
I’ve been muddling through using MySQL for some time, but it’s still not really
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
I am fetching some information from mysql database and I am displaying it using
I'm using MySQL and InnoDB and I've run into some problem recently. This is
I have just added a null password field to a mysql table using this

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.