title: Mysql insert into with select distinct
body: <p>i'm using java with mysql,i have this code in mysql </p>
  
  <p><code>SELECT DISTINCT date(datecreat) as datetemp
  , (SELECT max(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as maxt
  , (SELECT min(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as mint
  , (SELECT avg(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as avgt
  , (SELECT max(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as maxh
  , (SELECT min(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as minh
  , (SELECT avg(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as avgh
  , (SELECT max(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as maxp
  , (SELECT min(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as minp
  , (SELECT avg(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) as avgp  FROM akdb.iotdatas where (serialnum ='0000000000000');</code></p>
  
  <p>the result is like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2dfJk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2dfJk.png" alt="enter image description here"></a>
  but i want to insert this data into other table using this code</p>
  
  <p><code>insert into akdb.climdatas(hightemp,lowtemp,avgtemp,highhum,lowhum,avghum,highpress,lowpress,avgpress,dateinsert,zonedatas)values(maxt,mint,avgt,maxh,minh,avgh,maxp,minp,avgp,datetemp,'zone h');</code></p>
  
  <p>here the problem is "maxt mint ..." are unknown, but if i use select into insert</p>
  
  <p><code>insert into akdb.climdatas(SELECT DISTINCT date(datecreat) as datetemp
              ,(SELECT max(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT min(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT avg(sensortemp) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT max(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT min(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT avg(sensorhum) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT max(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT min(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ) 
              , (SELECT avg(sensorpres) FROM akdb.iotdatas WHERE date(datecreat)=datetemp ),' zone h'FROM akdb.iotdatas where (serialnum ='0000000000000000'))</code></p>
  
  <p>the error is in the columns   "mysql column count doesn't match value count at row 1" </p>