| | |
Putting in action different rows in stored procedure
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
i wanna put 1st row in action with 2nd row... then 2nd with 3rd and go on...
i did this three records i got correct result but when i add more records... everything is involved... i tried many different combinations but no success..
i want to solve this in sql not with php or asp... ( which easiest way for me )
Table prop:
MyID (int), Name (char), Game(int), Total(int), High(int), Low(int)
Records:
1 AAA 16 641 49 31
2 BBB 16 636 45 32
3 CCC 18 711 49 33
...
begin
declare min_rec_id, max_rec_id, total_record, cursore int;
set min_rec_id = (select min(MyID) from mytable);
set max_rec_id = ( select max(MyID) from mytable );
set total_record = ( select count(*) from mytable);
set cursore = 0;
while min_rec_id <= max_rec_id do
set min_rec_id = cursore + 1;
select MyID, Name, Game, Total, High, Low,
( Total / Game ) as Avarage,
( (( Total / Game ) - ( select Total / Game from mytable where MyID = min_rec_id ) ) * ( select Game from mytable where MyID = min_rec_id ) ) as PointFromBelow,
( ( Total / Game ) + ( ( ( Total / Game ) - ( select Total / Game from mytable where MyID = min_rec_id ) ) * ( select Game from mytable where MyID= min_rec_id ) ) ) as Whole
from mytable ORDER BY WHOLE DESC, Name ASC;
end while;
end
i did this three records i got correct result but when i add more records... everything is involved... i tried many different combinations but no success..
i want to solve this in sql not with php or asp... ( which easiest way for me )
Table prop:
MyID (int), Name (char), Game(int), Total(int), High(int), Low(int)
Records:
1 AAA 16 641 49 31
2 BBB 16 636 45 32
3 CCC 18 711 49 33
...
begin
declare min_rec_id, max_rec_id, total_record, cursore int;
set min_rec_id = (select min(MyID) from mytable);
set max_rec_id = ( select max(MyID) from mytable );
set total_record = ( select count(*) from mytable);
set cursore = 0;
while min_rec_id <= max_rec_id do
set min_rec_id = cursore + 1;
select MyID, Name, Game, Total, High, Low,
( Total / Game ) as Avarage,
( (( Total / Game ) - ( select Total / Game from mytable where MyID = min_rec_id ) ) * ( select Game from mytable where MyID = min_rec_id ) ) as PointFromBelow,
( ( Total / Game ) + ( ( ( Total / Game ) - ( select Total / Game from mytable where MyID = min_rec_id ) ) * ( select Game from mytable where MyID= min_rec_id ) ) ) as Whole
from mytable ORDER BY WHOLE DESC, Name ASC;
end while;
end
Do a favour, leave me alone
![]() |
Similar Threads
- PHP MySQL 5.0 stored procedure (PHP)
- Calling and executing stored Procedure (C)
- Accesing tables rows in Stored procedure without using cursors (MS SQL)
- Pbm with stored procedure (Oracle)
- Can return a Stored Procedure Recordset (MS SQL)
- Help with a stored procedure (MS SQL)
- Help with Stored Procedure (MS SQL)
- how do I run a "disconnected" stored procedure (MS SQL)
- Stored procedure call with ADO (C)
Other Threads in the MySQL Forum
- Previous Thread: Problem on installing MySQL
- Next Thread: mysql error only on web page
| Thread Tools | Search this Thread |
1 agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright court crm data database design developer development distinct dui email enter enterprise error eudora facebook form foss gartner gnu government gpl greenit groupware hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron microsoft microsoftexchange mindtouch montywidenius multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opengovernment opensource operand oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





