我有两个要加入的查询
SELECT b.nickname,count(a.doctor_id)
FROM a_table a
join b_table b
on (a.doctor_id=b.id_user)
GROUP BY a.doctor_id
和
SELECT doctor_id, SUM(medicine) medicine, SUM(radiology) radiology,sum(lab) lab, sum(act) act
FROM (
SELECT MAX(doctor_id) doctor_id,
SUM(IF(pm='F', cost, NULL)) medicine,
SUM(IF(pm='R', cost, NULL)) radiology,
SUM(IF(pm='L', cost, NULL)) lab,
SUM(IF(pm='P', cost, NULL)) act
FROM c_table
GROUP BY Trans_No
) t
GROUP BY doctor_id
我已经尝试加入
SELECT b.nickname, count(a.doctor_id), SUM(medicine) medicine, SUM(radiology) radiology,sum(lab) lab, sum(act) act
FROM (
SELECT MAX(doctor_id) doctor_id,
SUM(IF(pm='F', cost, NULL)) medicine,
SUM(IF(pm='R', cost, NULL)) radiology,
SUM(IF(pm='L', cost, NULL)) lab,
SUM(IF(pm='P', cost, NULL)) act
FROM c_table
GROUP BY Trans_No
) t
join a_table a on (a.doctor_id=t.doctor_id)
join b_table b on (a.doctor_id=b.id_user)
GROUP BY a.doctor_id
所有这些表都有大量数据(超过 200 万条数据),我已经设置了我的 CommandTimeout = 600 但它仍然没有响应
我是不是加入错了,还是只是对很多数据?我该怎么做才能得到结果?