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 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

I'm trying to convert some mysql tables from latin1 to utf8. I'm using the
Currently i'm using pretty much Unix + Mysql + Perl + Apache with some
I'm very confused in creating Tables in MySQL because I read some PHP tutorials
I have two MySQL tables: product has id , title , price and some
Im using smarty and mysql_real_escape_string() for user input, and when I insert some code
I've been using some basic AOP style solutions for cross-cutting concerns like security, logging,
I am using some nested layouts in Ruby on Rails, and in one of
Is there some library for using some sort of cursor over a file? I
I am using some custom controls one of which is a tooltip controller that
I am using some code which was originally taken from the Apple sample ViewTransitions

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.