Jump to content

Counting a subquery


Aeolus

Recommended Posts

I would really like to count this > I'd like to know how many rows are returning with matching c_id, basically, how many rows am I selecting here.. :)

 

Version 5.0.51b

 

INSERT INTO `e_result` ( `c_id`, `name`, `d_score`, `c_score`, `j_score`, `score`, `rank` )
SELECT
    $c_id,
    a.`name`,
    a.`d_score`,
    a.`c_score`,
    a.`j_score`,
    a.`score`,
    @MYCOUNTER:= @MYCOUNTER + 1 AS `rank`
FROM (
    SELECT
        `name`,
        @DVAR:=(`nat_d` + `tra_d` + FLOOR( {$natModifierMin} + RAND() * ({$natModifierMax} - {$natModifierMin}))) AS `d_score`,
        @CVAR:=(`nat_c` + `tra_c` + FLOOR( {$natModifierMin} + RAND() * ({$natModifierMax} - {$natModifierMin}))) AS `c_score`,
        @JVAR:=(`nat_j` + `tra_j` + FLOOR( {$natModifierMin} + RAND() * ({$natModifierMax} - {$natModifierMin}))) AS `j_score`,
        @DVAR + @CVAR + @JVAR AS `score`
    FROM `horses`
    WHERE `c_id`=$c_id
) AS `a`
WHERE 1=1
ORDER BY a.`score`

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.