更高效的MYSQL Wordpress加入/查看查询

时间:2015-12-14 23:12:42

标签: mysql wordpress

我当前的查询列出了来自WordPress用户/ usermeta数据库的一些信息,但是没有完成,减慢并且几乎停止其操作直到我停止该过程。

有更有效的方法来执行此查询吗?我认为选择所有数据并将其放在另一个表中以便更容易报告会更好。但是,我对MYSQL并不擅长,因此不确定最佳方法是什么。

SELECT 
u1.ID, 
u1.user_login, 
u1.user_email, 
m1.meta_value AS Gender, 
m2.meta_value AS Username,
m3.meta_value AS Country, 
m4.meta_value AS PassedSup,
m5.meta_value AS StartbeingSup,
m6.meta_value AS StoppedbeingSup,
m7.meta_value AS PassedTutor,
m8.meta_value AS CurrentlyaTutor,
m9.meta_value AS StartBeingTutor,
m10.meta_value AS StopBeingTutor,
m11.meta_value AS NoOfChildren,
m12.meta_value AS CurrentSupervisor,
m13.meta_value AS SecondSupervisor,
m14.meta_value AS Volunteer,
m15.meta_value AS VolunteerStart,
m16.meta_value AS VolunteerEnd,
m17.meta_value AS SupervisorName,
m18.meta_value AS NameOfTutor,
m19.meta_value AS DBSNo,
m20.meta_value AS DBSStart,
m21.meta_value AS Ref2
FROM wp_users u1
JOIN wp_usermeta m1 ON ( m1.user_id = u1.ID AND m1.meta_key = 'gender')
JOIN wp_usermeta m2 ON ( m2.user_id = u1.ID AND m2.meta_key = 'username_or_email')
JOIN wp_usermeta m3 ON ( m3.user_id = u1.ID AND m3.meta_key = 'country')
JOIN wp_usermeta m4 ON ( m4.user_id = u1.ID AND m4.meta_key = 'date_supervizor')
JOIN wp_usermeta m5 ON ( m5.user_id = u1.ID AND m5.meta_key = 'sup_start_date')
JOIN wp_usermeta m6 ON ( m6.user_id = u1.ID AND m6.meta_key = 'sup_end_date')
JOIN wp_usermeta m7 ON ( m7.user_id = u1.ID AND m7.meta_key = 'date_tutor')
JOIN wp_usermeta m8 ON ( m8.user_id = u1.ID AND m8.meta_key = 'is_tutor')
JOIN wp_usermeta m9 ON ( m9.user_id = u1.ID AND m9.meta_key = 'tutor_start')
JOIN wp_usermeta m10 ON ( m10.user_id = u1.ID AND m10.meta_key = 'tutor_end')
JOIN wp_usermeta m11 ON ( m11.user_id = u1.ID AND m11.meta_key = 'no_child')
JOIN wp_usermeta m12 ON ( m12.user_id = u1.ID AND m12.meta_key = 'Current_Supervizor')
JOIN wp_usermeta m13 ON ( m13.user_id = u1.ID AND m13.meta_key = 'supervizor_2')
JOIN wp_usermeta m14 ON ( m14.user_id = u1.ID AND m14.meta_key = 'volunteer')
JOIN wp_usermeta m15 ON ( m15.user_id = u1.ID AND m15.meta_key = 'volunteer_start')
JOIN wp_usermeta m16 ON ( m16.user_id = u1.ID AND m16.meta_key = 'volunteer_end')
JOIN wp_usermeta m17 ON ( m17.user_id = u1.ID AND m17.meta_key = 'Name_of_tutor')
JOIN wp_usermeta m18 ON ( m18.user_id = u1.ID AND m18.meta_key = 'DBS_NO')
JOIN wp_usermeta m19 ON ( m19.user_id = u1.ID AND m19.meta_key = 'DBS_start_date')
JOIN wp_usermeta m20 ON ( m20.user_id = u1.ID AND m20.meta_key = 'date_membership_passed')
JOIN wp_usermeta m21 ON ( m21.user_id = u1.ID AND m21.meta_key = 'ref_2')

0 个答案:

没有答案