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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:39:14+00:00 2026-06-07T16:39:14+00:00

I have the following sql which selects the most recurring row first based on

  • 0

I have the following sql which selects the most recurring row first based on the column “reported”

 $datan = mysql_query("
   SELECT *, COUNT(reported) AS ct
   FROM profile_reports
   WHERE open = '1'
   GROUP BY reported
   ORDER BY ct DESC
   LIMIT 1
 ") or die(mysql_error());

I want my sql to also check which ‘reporter’ (each is a number associated with a user) has the best percentage of useful reports, which is determined this way:

((raction > 0 AND raction < 99 AND open = '0' AND reporter = 'reporter') / (reporter = 'reporter' AND open = '0')) * 100

…and show the rows with highest percentage first. It’s a little tricky because no initial reporter is set.

Here’s a sample table:

+----+----------+----------+-------+----------+
| id | reporter | reported | open  |  raction |
+----+----------+----------+-------+----------+
|  1 |       24 |    26    |  0    |  3       |
|  2 |       24 |    23    |  0    |  0       |
|  3 |       24 |    29    |  1    |          |
|  4 |       12 |    29    |  0    |  4       |
|  5 |       12 |    29    |  1    |          |
|  6 |       24 |    21    |  1    |  0       |
+----+----------+----------+-------+----------+

I want it to see that there are more reports about user 29(column: reported), then check which reporting user(column: reporter) has the best percentage (based on the line of code above), in this case user 12, and display their report

  • 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-07T16:39:17+00:00Added an answer on June 7, 2026 at 4:39 pm

    Its actually pretty easy in just take the sums of your conditions and divide. In order to get the “Reported” correctly you’ll need to use an inline view to find the highest report.

    SELECT pr.*, 
           ( Sum(pr.raction > 0 
                 AND pr.raction < 99 
                 AND pr.open = '0' 
                 AND pr.reported = t.reported) / Sum(pr.reported = t.reported 
                                                     AND pr.open = '0') ) * 100 AS 
           usefull 
    FROM   profile_reports pr, 
           (SELECT reported 
            FROM   profile_reports 
            WHERE  open = '1' 
            GROUP  BY reported 
            ORDER  BY Count(reported) DESC 
            LIMIT  1) t 
    GROUP  BY reporter 
    ORDER  BY usefull DESC 
    LIMIT  1 
    

    demo

    Output

    | ID | REPORTER | REPORTED | OPEN | RACTION | USEFULL |
    -------------------------------------------------------
    |  4 |       12 |       29 |    0 |       4 |     100 |
    

    I haven’t done everything for you. You will have to decide what to do if the divisor is zero

    Note in just about everything but MySQL you would need to use CASE

       SUM ( CASE WHEN raction > 0 AND .... THEN 1 ELSE 0 END) / ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL statement which has a very bad performance: SELECT frmInstLastModifiedDate
I have the following piece of SQL: select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) which comes through as
I have the following which works in SQL Query Analyzer . select oh.* from
I have a drop-down list which is generated based on the following sql query:
I have following sql which is show previous days records from table. SELECT *
I have the following SQL which creates a friends list with other info: SELECT
I have the following SQL statement which returns a single record as expected: select
I have the following code: $sql = mysql_query(SELECT id FROM logins WHERE id=' .
I have the following SQL statement which seems to be deleting every row in
I have a following oracle sql query in which START_DATE is a number column

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.