Java 使用select distinct将Mysql插入到

Java 使用select distinct将Mysql插入到,java,mysql,select,insert,distinct,Java,Mysql,Select,Insert,Distinct,我在mysql中使用java,我在mysql中有这段代码 选择不同的datedatecreat作为datetemp ,从akdb.iotdatas中选择maxsensortemp,其中datedatecreat=datetemp作为maxt ,从akdb.iotdatas中选择minsensortemp,其中datedatecreat=datetemp为mint ,从akdb.iotdatas中选择avgsensortemp,其中datedatecreat=datetemp作为avgt ,从ak

我在mysql中使用java,我在mysql中有这段代码

选择不同的datedatecreat作为datetemp ,从akdb.iotdatas中选择maxsensortemp,其中datedatecreat=datetemp作为maxt ,从akdb.iotdatas中选择minsensortemp,其中datedatecreat=datetemp为mint ,从akdb.iotdatas中选择avgsensortemp,其中datedatecreat=datetemp作为avgt ,从akdb.iotdatas中选择maxsensorhum,其中datedatecreat=datetemp为maxh ,从akdb.iotdatas中选择minsensorhum,其中datedatecreat=datetemp为minh ,从akdb.iotdatas中选择avgsensorhum,其中datedatecreat=datetemp作为avgh ,从akdb.iotdatas中选择maxsensorpres,其中datedatecreat=datetemp为maxp ,从akdb.iotdatas中选择MinSensorPress,其中datedatecreat=datetemp作为minp ,从akdb.iotdatas中选择avgsensorpres,其中datedatecreat=datetemp作为akdb.iotdatas中的avgp,其中serialnum='0000000000000'

结果如下:

但是我想用这个代码将这个数据插入到其他表中

插入akdb.climdatashightemp,lowtemp,avgtemp,highum,lowhum,avghum,highpress,lowpress,avgpress,dateinsert,zonedasasvaluesmart,mint,avgt,maxh,minh,avgh,maxp,minp,avgp,datetemp,datetemp,'zone h'

这里的问题是maxt mint。。。未知,但如果使用“选择插入”

插入akdb.climdatasSELECT DISTINCT datedate创建为datetemp ,从akdb.iotdatas中选择maxsensortemp,其中datedatecreat=datetemp ,从akdb.iotdatas中选择minsensortemp,其中datedatecreat=datetemp ,从akdb.iotdatas中选择avgsensortemp,其中datedatecreat=datetemp ,从akdb.iotdatas中选择maxsensorhum,其中datedatecreat=datetemp ,从akdb.iotdatas中选择minsensorhum,其中datedatecreat=datetemp ,从akdb.iotdatas中选择avgsensorhum,其中datedatecreat=datetemp ,从akdb.iotdatas中选择maxsensorpres,其中datedatecreat=datetemp ,从akdb.iotdatas中选择MinSensorPress,其中datedatecreat=datetemp ,从akdb.iotdatas中选择AvgSensorPress,其中datedatecreat=datetemp,从akdb.iotdatas中选择zone h,其中serialnum='0000000000000000'


错误在于第1行的列mysql列计数与值计数不匹配。看起来climdatas表中的列数多于或少于11列。在insert语句中,指定以逗号分隔的列列表


climdatas表的定义是什么?除了要插入的列之外,还有其他列吗?、id、hightemp、lowttemp、avgtemp、highhum、lowhum、avghum、highpress、lowpress、avgpress、dateinsert、zonedatas但id会自动递增,在这种情况下,我已经用值测试过了,尝试将第一个insert语句与第二个insert语句结合起来—基本上包括要插入的列的列表。猜测一下,它也在尝试插入id列。如何将'datetemp'列从第一列更改为最后一列?请参阅Keyur Panchal的答案,您只需将列表中的列移动到您期望的数据位置。我使用了此语句和相同的问题,因为结果表在第一列中给出了“datetemp”,就像上面的表和“climdatas”中一样,“dateinsert”列在最后一列之前,然后更改列的顺序。你可以做到。请参阅更新的答案。不要更改select查询。保持原样。当然。欢迎光临如果我不想重复约会怎么办?我不明白你的意思。请你再描述一下好吗?
insert into akdb.climdatas (dateinsert,hightemp,lowtemp,avgtemp,highhum,lowhum,avghum,highpress,lowpress,avgpress,zonedatas)
(your select query goes here.)