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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:22:58+00:00 2026-05-30T19:22:58+00:00

I have this table select * from points +———+——+——+ | NAME | Type |

  • 0

I have this table

select * from points

+---------+------+------+
| NAME    | Type | RANK |
+---------+------+------+
| A       | H    |  90  |
| A       | M    | 100  |
| A       | H    | N/A  |
| A       | H    | N/A  |
| A       | H    | N/A  |
| B       | H    | 100  |
| B       | M    | 100  |
| B       | L    | 100  |
| C       | H    |  85  |
| C       | M    | 100  |
+---------+------+------+

I’m using this query

SELECT name,
       CAST(
       (      -- only have H, or only have M, or only have L:
         CASE WHEN  `# of H` = 0  AND  `# of M` = 0  THEN  100 * `# of active L` / `# of L`
              WHEN  `# of H` = 0  AND  `# of L` = 0  THEN  100 * `# of active M` / `# of M`
              WHEN  `# of M` = 0  AND  `# of L` = 0  THEN  100 * `# of active H` / `# of H`
              -- only have H & M, or only have H & L, or only have M & L:
              WHEN  `# of H` = 0  THEN  60 * `# of active M` / `# of M` + 40 * `# of active L` / `# of L`
              WHEN  `# of M` = 0  THEN  90 * `# of active H` / `# of H` + 20 * `# of active L` / `# of L`
              WHEN  `# of L` = 0  THEN  80 * `# of active H` / `# of H` + 20 * `# of active M` / `# of M`
              -- have all three:
              ELSE  70 * `# of active H` / `# of H` + 20 * `# of active M` / `# of M` + 10 * `# of active L` / `# of L`
         END
       ) AS SIGNED ) AS score
  FROM ( SELECT name,
                SUM(IF(         type = 'H', 1, 0))  AS `# of H`,
                SUM(IF(rank AND type = 'H', 1, 0))  AS `# of active H`,
                SUM(IF(         type = 'M', 1, 0))  AS `# of M`,
                SUM(IF(rank AND type = 'M', 1, 0))  AS `# of active M`,
                SUM(IF(         type = 'L', 1, 0))  AS `# of L`,
                SUM(IF(rank AND type = 'L', 1, 0))  AS `# of active L`
           FROM points
          GROUP BY name
       ) t
 ORDER
    BY name
;

I get this Output

+---------+-------+
| NAME    | SCORE |
+---------+-------+
| A       |   60  | <--[(2xH)=40 + (1xM)=20] =60
| B       |  100  | <--[(1xH)=70 + (1xM)=20 + (1xL)=10] =100
| C       |  100  | <--[(1xH)=80 + (1xM)=20] =100
+---------+-------+

I need this Desired output

+---------+-------+
| NAME    | SCORE |
+---------+-------+
| A       |   36  | <--[70/4=(17.5 per H) therefore (17.5)*(rank of that h: 90%)=15.75 + (M values, which equals 20/1 =20 Therefore: rank of that m:100% * 20 = 100) = 36 rounded
| B       |  100  | <--[(1xH)=70 + (1xM)=20 + (1xL)=10] =100
| C       |   88  | <--[(1xH)=80 + (1xM)=20] =100
+---------+-------+

Computations required:

  • Type can have only three values: {H, M, L};
  • When all values are present, they are graded as followed:

    H=70 M=20 L=10

  • If an name has more than one kind of Type (H, M, or L) then points are distributed as followed:

  • H/(number of H) ; M/(number of M); L/(number of L)

— Example: A has 4 H therefore 70 / 4 = 17.5 for each H

  • But some names have a complete set with out having all ‘Types.
    — example : C has Type values: ‘H&M` only

  • Now Type ‘H’ and ‘M’ have to equal 100 for C.

So when only ‘H` and ‘M’ are present they are graded as followed:

H=80 M=20

  • Equally if another animal comes along with only two Type values M & L they will be graded as followed:

M=60 L=40

  • Equally if another animal comes along with only two Type values H & L they will be graded as followed:

H=90 L=10

And also

  • if only H is presnet H=100

  • if only M is presnet M=100

  • if only L is presnet L=100

  • 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-30T19:23:00+00:00Added an answer on May 30, 2026 at 7:23 pm

    This looks familiar. 🙂

    Your description is inconsistent in a number of places — for example, your “desired output” for A uses 70 and 20, even though no As have type L — but if you mean what I think you do, then the main change you need is to change SUM(IF(rank AND type = 'H', 1, 0)) AS `# of active H` to SUM(IF(type = 'H', rank / 100.0, 0)) AS `rank of H` (and likewise for M and L), and change all references to `# of active H` to refer to `rank of H` instead. This way each record will be included in proportion to its rank, rather than being an all-or-nothing thing.

    You’ll also want to use ROUND instead of CAST — or in addition to CAST — when converting your score to an integer.

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

Sidebar

Related Questions

I have the following table: select * from points +---------+-------------------+------+------+ | NAME | TITLE
I have very simple select like this: SELECT * FROM table WHERE column1 IN
If i have a parameterized SQL statement like this: SELECT * FROM table WHERE
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have a select like this: SELECT field1, field2, field3 FROM table WHERE field1=
Let's say I have this query: select * from table1 r where r.x =
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
Well I have this - Table DimDate- Date Table Employee- Id,Name,Points,Date Now the Employee
I have a table. In this table have select element. How can I find

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.