如果出现多行,如何在php mysql中执行select query
内部存储过程?
首先我想distinct (chapter_id)
从a table (practice_test_result)
特定学生那里获取
然后代表该distinct(chapter_id )
运行一个查询以生成关联数组
我面临的问题是:
while( row found ){
/* here i perform the SELECT SUM(total_question) - SUM(total_incomplete) , SUM(total_correct) into totalattempt,talcorrect FROM practice_test_summary WHERE student_id =studentid AND chapter_id =chapterid;
set chpapter_successrate[i] =(totalcorrect * 100)/totalattempt; */
}
下面的代码了解更多关于我到底想要什么的问题
DELIMITER //
DROP PROCEDURE IF EXISTS get_result//
CREATE PROCEDURE get_result(studentid INT,courseid INT,out chpapter_successrate decimal(10,2))
BEGIN
SELECT distinct(chapter_id) FROM practice_test_result WHERE course_id =courseid AND student_id =studentid;
set chapterid=chapter_id;
//here i want to use while loop for all chapter_id and behalf of these chpater id's perform another select statement for performing successrate of specific chapter and store that into an array and return that array as out variable
SELECT SUM(total_question) - SUM(total_incomplete) , SUM(total_correct) into totalattempt,talcorrect FROM practice_test_summary WHERE student_id =studentid AND chapter_id =chapterid;
set chpapter_successrate[i] =(totalcorrect * 100)/totalattempt;
END//