MySQL临时表建立
MySQL建立临时表的语句如下:
CREATE TEMPORARY TABLE tmp (
article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
price DOUBLE(16,2) DEFAULT '0.00' NOT NULL);
--LOCK TABLES article read;
--先插入数据到临时表
INSERT INTO tmp SELECT article, MAX(price) from shop GROUP BY article;
--查询临时表数据
SELECT article, dealer, price from shop, tmpWHERE shop.article=tmp.articel AND shop.price=tmp.price;
--UNLOCK TABLES;
DROP TABLE tmp;
相关文档: