生成臨時表code
DROP TABLE IF EXISTS temp1; CREATE TEMPORARY TABLE temp1 SELECT userId,createTime FROM `user`;
查看臨時表索引
SELECT * FROM temp1
添加索引ip
ALTER TABLE temp1 ADD INDEX id_userId(`userId`);
使用it
DROP TABLE IF EXISTS temp1; CREATE TEMPORARY TABLE temp1 SELECT A.id,IF(A.status=3,1,0) '實名',IF(A.authStatus=3,1,0) '身份',IF(D.truckId IS NULL,0,1) '車輛',A.createTime, -- B.`recommendMobile`,C.`mobile`, CASE WHEN B.recommendMobile IS NULL THEN '無推薦人' WHEN B.recommendMobile IS NOT NULL AND C.mobile IS NULL THEN '非地推推薦' ELSE '地推推薦' END AS recomType FROM TopJet560.`user` A LEFT JOIN TopJet560.recommendRelationship B ON A.id= B.`recommendedUserId` LEFT JOIN test.`mobile0815` C ON B.`recommendMobile` = C.`mobile` LEFT JOIN TopJet560.`driverTruckInfo` D ON A.id = D.driverId AND D.auditStatus =2 WHERE A.createTime >= '2017-06-01' AND A.createTime <'2017-07-01' AND A.type =1 ALTER TABLE temp1 ADD INDEX id_userId(`id`); SELECT * FROM temp1;