简体   繁体   中英

How to sum m1 and m2 in this query

I have a query for result show Now, I need sum m1, m2

Query is:

select metraj, fee, tedad, fee_tedad,
       metraj * fee AS m1,
       tedad * fee_tedad AS m2 
from content 
where id = 54 

Do like this

select metraj, fee, tedad, fee_tedad,
       metraj * fee AS m1,
       tedad * fee_tedad AS m2,
       metraj * fee+tedad * fee_tedad as sum
from content 
where id = 54
select metraj, fee, tedad, fee_tedad, metraj * fee AS m1, tedad * fee_tedad AS m2, mtraj * fee + tedad * fee_tedad as m1_plus_m2 from content where id = 54

The following should work :

select metraj, fee, tedad, fee_tedad, (metraj * fee) + (tedad * fee_tedad) AS someVariable, from content where id = 54 

If you need both m1 and m2 also then use the following :

select metraj, fee, tedad, fee_tedad, metraj * fee AS m1, tedad *fee_tedad AS m2, (metraj * fee) + (tedad * fee_tedad) AS someVariable  from content  where id = 54 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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