Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

mysql - Getting the max value after being multiplied and added

please help me with the codes I'm working with right now. I just want to show the distinct Max value from the table After being multiplied and added the the 2 columns from 2 different tables.

HERE is my SQL statement for my table:

SELECT ol.*
     , SUM((ol.OrderedQuantity)*(SELECT p.ProductStandardPrice FROM product_t p WHERE p.ProductID=ol.ProductID)) AS TotalAmount  
  FROM orderline_t ol 
 GROUP 
    BY ol.OrderID

output table shows only the value inside the box using max.

enter image description here

question from:https://stackoverflow.com/questions/65857097/getting-the-max-value-after-being-multiplied-and-added

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

1 Reply

0 votes
by (71.8m points)

I don't follow exactly what you want to do. However, your query would more colloquially and accurately be written using JOIN. If you want the total per order then you don't want all those extraneous columns on the row:

SELECT ol.OrderId,
       SUM((ol.OrderedQuantity * p.ProductStandardPrice) AS TotalAmount  
FROM orderline_t ol JOIN
     product_t p 
     ON p.ProductID = ol.ProductID
GROUP BY ol.Order;

I suspect that starting with a working query will get you closer to the solution you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...