Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

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

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
question from:https://stackoverflow.com/questions/5693259/how-can-a-query-multiply-2-cell-for-each-row-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...