1:原来MySql也可以有临时表,这点还是不错,
DROP temporary TABLE if EXISTS mytempdatatable; CREATE TEMPORARY table mytempdatatable SELECT tu.unit_session_uid,us.unit_session_sdate,us.unit_session_edate FROM unit tu INNER JOIN unit_session us ON tu.uni_id=us.uni_id AND us.unit_session_type='1' WHERE tu.uni_id='47891229-62f4-4ab8-a95c-904e6dc037c0' AND tu.isdel=0 and us.isdel=0 LIMIT 1; SELECT * FROM mytempdatatable;
2:不过执行之后,还可以单独使用到,也没有删除,这点和Sqlserver有些不一样
3:来一个带变量的操作,这个感觉还是很不错的,嘻嘻,越来越觉得mysql可爱了
DROP temporary TABLE if EXISTS mytempdatatable; CREATE TEMPORARY table mytempdatatable SELECT tu.unit_session_uid,us.unit_session_sdate,us.unit_session_edate FROM unit tu INNER JOIN unit_session us ON tu.uni_id=us.uni_id AND us.unit_session_type='1' WHERE tu.uni_id='47891229-62f4-4ab8-a95c-904e6dc037c0' AND tu.isdel=0 and us.isdel=0 LIMIT 1; SET @sd='1990-01-01',@ed='1990-01-01'; -- SELECT * FROM mytempdatatable; SET @sd=(SELECT unit_session_sdate FROM mytempdatatable); SET @ed=(SELECT unit_session_edate FROM mytempdatatable); SELECT @sd,@ed;