mysql TEMPORARY TABLE
生成临时表
DROP TABLE IF EXISTS temp1;
CREATE TEMPORARY TABLE temp1
SELECT userId,createTime FROM `user`;
查看临时表
SELECT * FROM temp1
添加索引
ALTER TABLE temp1 ADD INDEX id_userId(`userId`);
使用
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;
```
专注数据分析
欢迎转载并注明出处
```