phpmyadmin

Re: phpmyadmin

- M Numata の投稿
返信数: 0

Yoshidaさま


御礼が遅れてしまい申し訳ありません。

元々のSQLの検索条件が足りていなくて、複数のロールが返されてしまう状態でした。確認しなおして、希望していた結果が得られました。

SQLのテーブルをうまく使えればデータ取得も容易になりそうなのでしっかり勉強したいと思います

ありがとうございました。


以下備忘録として(長々すみません)

取得するデータ: 購入者、購入日時、コースid等

取得条件: 指定日内、購入したコースのロールが"5 学生"のもの

SELECT TBLCOURSE.idnumber, TBLUSER.username, TBLUSERENROLMENT.timecreated,TBLCOURSE.shortname, TBLROLEASSIGN.roleid, TBLUSER.lastname, TBLUSER.firstname, TBLUSER.email,  TBLUSERENROLMENT.userid 

FROM mdl_user_enrolments as TBLUSERENROLMENT 

INNER JOIN mdl_user as TBLUSER ON ( TBLUSERENROLMENT.userid = TBLUSER.id ) 

INNER JOIN mdl_enrol as TBLENROL ON ( TBLUSERENROLMENT.enrolid = TBLENROL.id ) 

INNER JOIN mdl_course as TBLCOURSE ON (TBLENROL.courseid = TBLCOURSE.id) 

INNER JOIN mdl_context as TBLCONTEXT  ON (TBLCONTEXT.contextlevel = '50' AND TBLCOURSE.id = TBLCONTEXT.instanceid) 

INNER JOIN mdl_role_assignments as TBLROLEASSIGN ON (TBLUSER.id=TBLROLEASSIGN.userid AND TBLCONTEXT.id = TBLROLEASSIGN.contextid) 

WHERE from_unixtime(TBLUSERENROLMENT.timecreated) BETWEEN "2016-09-20" AND "2016-09-30 23:59:59"

AND TBLROLEASSIGN.roleid = '5' 

ORDER BY TBLUSERENROLMENT.timecreated DESC