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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:13:24+00:00 2026-06-08T01:13:24+00:00

I’ve come to find out that the following SQL is not possible due to

  • 0

I’ve come to find out that the following SQL is not possible due to correlated subqueries within MySQL not having access to the outer query, when I run the below query I get the error of “player.playerid not found”

SELECT player.position, player.playerid, adp.average_draft_position FROM player, (
    SELECT ((ad_p.mult + ad_p.pick_sum) / ad_p.total_mocks) AS average_draft_position FROM (
        SELECT draft_c.total_mocks as total_mocks, 
               ((draft_c.total_mocks - player_c.total_picks) * 252) AS mult, 
               SUM(overall_pick) AS pick_sum FROM draft_history JOIN drafts ON drafts.id = draft_history.draftid, 
            (
                SELECT COUNT(drafts.id) AS total_mocks FROM drafts WHERE type = 3
            ) AS draft_c, (
                SELECT COUNT(draft_history.playerid) AS total_picks FROM draft_history WHERE draft_history.playerid = player.playerid
            ) AS player_c WHERE draft_history.playerid = player.playerid
    ) AS ad_p
) AS adp WHERE player.sportid = 1 AND player.position IN ('x', 'y', 'z') ORDER BY adp.average_draft_position ASC

I am attempting to use the following as a subquery in the above,

SELECT ((adp.mult + adp.pick_sum) / adp.total_mocks) AS average_draft_position FROM (
            SELECT draft_c.total_mocks as total_mocks, ((draft_c.total_mocks - player_c.total_picks) * 252) AS mult, SUM(overall_pick) AS pick_sum FROM draft_history JOIN drafts ON drafts.id = draft_history.draftid, 
            (
                SELECT COUNT(id) AS total_mocks FROM drafts WHERE type = :type
            ) AS draft_c, (
                SELECT COUNT(playerid) AS total_picks FROM draft_history WHERE playerid = :playerid
            ) AS player_c WHERE playerid = :playerid
        ) as adp

This will determine the average position a user has been picked throughout history, including cases when the user was not selected by applying a weight to their total sum, this one works.

The first query above is attempting to take that and select all users that currently exist in the given positions get the average position and sort by it.

I’m not so great at SQL so I could probably be doing this better and If I could explain this better please let me know.

Problem solved with the given query,

SELECT position, 
       playerid,
       ((((adp.total_mocks - adp.participated_mocks) * 252) + adp.pick_sum) / adp.total_mocks) AS average_draft_position
FROM 
(      
    SELECT player.position, 
           player.playerid,
           (SELECT COUNT(drafts.id) FROM drafts WHERE type = 3) as total_mocks,
           COUNT(draft_history.playerid) as participated_mocks,
           SUM(overall_pick) AS pick_sum 
    FROM draft_history 
    INNER JOIN drafts 
      ON drafts.id = draft_history.draftid
    INNER JOIN player
      ON player.sportid = 1
     AND player.position IN ('QB') 
     AND draft_history.playerid = player.playerid
    GROUP BY player.position, player.playerid
) adp ORDER BY average_draft_position ASC 
  • 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-08T01:13:25+00:00Added an answer on June 8, 2026 at 1:13 am

    I think I can understand this.
    try this:

    select position, 
           playerid,
           ((adp.mult + adp.pick_sum) / adp.total_mocks) AS average_draft_position
    from 
    (      
        SELECT player.position, 
               player.playerid,
               (SELECT COUNT(drafts.id) FROM drafts WHERE type = 3) as total_mocks
               (
                    (SELECT COUNT(drafts.id) FROM drafts WHERE type = 3) 
                  - COUNT(draft_history.playerid)
               )*252 as mult,
               SUM(overall_pick) AS pick_sum 
        FROM draft_history 
        INNER JOIN drafts 
          ON drafts.id = draft_history.draftid
        INNER JOIN player
          ON player.sportid = 1
         AND player.position IN ('x', 'y', 'z') 
         AND draft_history.playerid = player.playerid
        group by player.position, player.playerid
    ) adp
    order by 3 asc
    

    if “(SELECT COUNT(drafts.id) FROM drafts WHERE type = 3)” is a constant ,you can :

    SELECT COUNT(drafts.id) FROM drafts WHERE type = 3 into @total_mocks;

    then use @total_mocks replace the expression “(SELECT COUNT(drafts.id) FROM drafts WHERE type = 3)”

    just try it

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

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.