How can a query multiply 2 cell for each row MySQL?

Arne Nouwynck picture Arne Nouwynck · Apr 17, 2011 · Viewed 101.2k times · Source

I want to multiply 2 cells for each row and put the value of that in the last column called Total. Can this be done by a normal query?

Example:

Pieces | Price | Total
6      |   4   |  null // should be 24
2      |  10   |  null // should be 10

Answer

Prescott picture Prescott · Apr 17, 2011

Use this:

SELECT 
    Pieces, Price, 
    Pieces * Price as 'Total' 
FROM myTable