How can I solve with query: I want to calculate out the cubic meter for the whole table in tbale1 and insert the total cubic meter in table2 with the wood type and dimension A. After the data is inserted in to table2 table1 all data need to be cleand out (delet from table).
teble1
wood | dimension A | dimension B | dimension C |
---|---|---|---|
poplar | 2.5 | 0.5 | 0.029 |
poplar | 2.5 | 0.35 | 0.029 |
table2
wood | dimension A | cubic |
---|---|---|
poplar | 2.5 | 0.0616 |
CodePudding user response:
Guessing you want to calculate the cubic meter for each wood and dimensionA, you can do so while also inserting them into table2 with:
INSERT INTO table2
(SELECT t1.wood, t1.dimensionA, ROUND(SUM(t1.dimensionA * t1.dimensionB * t1.dimensionC),5)
FROM table1 t1
GROUP BY wood,dimensionA);
About the second part (cleaning out the data),I dont really understand the purpose of doing so but you can do it simply by using DELETE FROM table1
small fiddle i used for testing.
CodePudding user response:
$insertdata = INSERT INTO table2() SELECT column1,column2 FROM table1;
if($insertdata)
{
//write delete query here
}