简体   繁体   English

从mysql中的别名获取总和

[英]Getting sum from alias in mysql

This is my sql code 这是我的sql代码

SELECT qty, unitprice, qty * unitprice as Stock FROM item

Form this i want to get the SUM of Stock 形成这个我想得到股票的总和

It is not clear what you are asking here. 目前尚不清楚你在这里问的是什么。 I'm not sure about the ultimate goal you are trying to achieve, but this will bring you SUM of all qty * unitprice : 我不知道你想实现的终极目标,但是这会给你带来SUM所有的qty * unitprice

SELECT qty, unitprice, SUM(qty * unitprice) as Stock FROM item

And this is literally bring you SUM of Stock : 这真的带给你Stock SUM

SELECT SUM(Stock) as SUM_OF_STOCK
FROM 
    (SELECT qty, unitprice, qty * unitprice as Stock 
     FROM item)

If none of above query fit your needs, I think you really need to edit the question and elaborate more on what you are trying achieve. 如果以上查询都不符合您的需求,我认为您确实需要编辑问题并详细说明您尝试实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM