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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:38:46+00:00 2026-06-12T12:38:46+00:00

Bear with me, I’m SQL.stupid. I’ve finally learned that one should use views instead

  • 0

Bear with me, I’m SQL.stupid. I’ve finally learned that one should use views instead of crons when possible. Now, I have a view within a view question.

My stack friends have gotten me this far:

CREATE VIEW tbl.sums as SELECT 

table2.id, 

SUM( table1.column1 * 2 ) as column1Sum,

SUM( table1.column2 * 2 ) as column2Sum,

SUM( table1.column3 * 2 ) as column3Sum

FROM table1, table2
WHERE table1.table2_id = table2.id GROUP BY table2.id

I’d like to put in a 5th column into the view that’s an equally-weighted rank of the other 3.

So, the equation would be something like (1/3)*percentile(column1Sum) + (1/3)*percentile(column2Sum) + (1/3)*percentile(column3Sum) where “percentile()” is the percentile rank of the column vs the rest of the column.

Please excuse the lack of clarity. This really isn’t my specialty. Will edit as much as needed.

Thank-you very much in advance!

Percentile Clarity

In my case, percentile is the percentage rank from highest to lowest of a given column adjusted for repeats. So for a column with 100 values, the one with the largest, would be 100%, the one with the lowest would be 0% (or would it be 1%?). If there were 100 but 50 duplicates, the bottom two would share 2%.

  • 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-12T12:38:48+00:00Added an answer on June 12, 2026 at 12:38 pm
    CREATE VIEW tbl.sums as SELECT 
        tmp.*,
        (1/3)*(tmp.column1Sum+tmp.column2Sum+tmp.column3Sum)
    FROM (
        SELECT 
            table2.id, 
            SUM( table1.column1 * 2 ) as column1Sum,
            SUM( table1.column2 * 2 ) as column2Sum,
            SUM( table1.column3 * 2 ) as column3Sum
        FROM table1, table2
        WHERE table1.table2_id = table2.id GROUP BY table2.id
    ) AS tmp
    

    The equation does not make much sense to me, I think there must be something wrong, or I didn’t really get what the percentile is supposed to be… So I put just whatever, as long as it depends on the fields of the subquery.

    If you hadn’t used subqueries, but used instead column1Sum directly you would get an error about an unknown column.

    Otherwise you could just rewrite the formula used to calculate the sums instead of using its name. But I guess this is not practical for your use case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

bear with me, I've been using wxPython for all of one day now. Short
Please bear in mind that I'm totally new to Rails when answering this.My question
Bear with me, this one is hard to explain. I hope some hero out
Bear with me on this one! Right. Clicking on a link button on a
Bear with me as I try to simplify my issue as much as possible.
Please bear with me on this one. I am first going to describe an
Bear with me on this one. I have an iphone application. It is a
Bear with me as I describe the issue. An MVC3 application making use of
Bear with me, this one's not very easy to explain... I'm trying to configure
Bear with me, I'm new to intermediate. My question is - When should I

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.