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
https://forums.phpfreaks.com/topic/170995-counting-a-subquery/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.