Heim  >  Artikel  >  Backend-Entwicklung  >  一下大家,打了三个小时了

一下大家,打了三个小时了

WBOY
WBOYOriginal
2016-06-23 13:47:44999Durchsuche

小人不才,mysql学得一塌糊涂..........................................急求大家帮助..........................

我的目的是将查询后的结果作为一张临时表存放起来,我的sql语句如下:


select a.value,a.id,b.value from a,b where a.value=b.value as k;


居然报错...........................................请问正确的语法是什么??

两张表都是存在的


相应的字段也是存在的


我觉得应该是语法上面有错误,请问正确的语法是什么??

十万火急,万分感谢!!!!!!!!!!!!!!!!!!!!!


回复讨论(解决方案)

报错就有错误信息
而错误信息中已经给出了出现问题的位置

as k似乎有问题,去掉试试。

select * from (select a.value,a.id,b.value from a,b where a.value=b.value ) k;

select * from (select a.value,a.id,b.value from a,b where a.value=b.value ) k;



还是不行啊…………照着你的语句复制上去,还是出现错误...

应该只是一个语句方面的问题,我只是想将查询到的结果作为一张临时表存放起来而已的,很简单的,麻烦用心写写

报错就有错误信息
而错误信息中已经给出了出现问题的位置



版主大人救命啊,我我只是想将查询到的结果作为一张临时表k存放起来而已的,很简单的

你的语句是什么,贴出来看看。

create temporary table k select a.value,a.id,b.value from a,b where a.value=b.value

不过临时表只能生存在当前连接中




报错就有错误信息
而错误信息中已经给出了出现问题的位置



版主大人救命啊,我我只是想将查询到的结果作为一张临时表k存放起来而已的,很简单的

create table temp_table as select * from table; 

创建临时表是用create temporary table tablename,然后把数据插入。
在phpmyadmin运行可以看到结果

create temporary table k(  `a` varchar(20) NOT NULL,  `aid` int(11) NOT NULL,  `b` varchar(20) NOT NULL);insert into k(a,aid,b) select a.value,a.id,b.value from a,b where a.value=b.value;select * from k;

版主写的那句需要改一改。

create temporary table k select a.value as aval,a.id as aid,b.value as bval from a,b where a.value=b.value;select * from k;


否则会有两个value,导致出错。#1060 - Duplicate column name 'value' 

with k as (select a.value,a.id,b.value as value1 from a,b where a.value=b.value)select * from k
或者是
select * from (select a.value,a.id,b.value as value1 from a,b where a.value=b.value) k
需要注意的是select a.value,a.id,b.value这里不能有重复的字段

未结贴吗?还有问题?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php编码问题Nächster Artikel:动态添加的radio怎么向php传值