如何在Mysql查询中执行乘法运算?
如果我的查询是这样的:
"SELECT registration.hosteladmissionno,
registration.student_name,
registration.semester,
student_month.hosteladmissionno,
student_month.student_name,
student_month.semester,
messexp.billmonth,messexp.billyear ,messexp.perdayrate,student_month.days_mess
FROM registration,
student_month ,messexp,blockexp
WHERE student_month.hosteladmissionno = registration.hosteladmissionno
";
如何在此查询中执行乘法运算?说..乘法运算btw days_mess和
答案 0 :(得分:10)
乘法运算符为*
:
mysql> select 100 * 2;
+---------+
| 100 * 2 |
+---------+
| 200 |
+---------+
1 row in set (0.00 sec)
在您的情况下,如果您想要将两列的值相乘,则可以使用这些列,并在它们之间使用*
运算符:
select column1 * column2 as result
from your_table
where ...
答案 1 :(得分:1)
select (days_mess * anotherFiled) as anyName
答案 2 :(得分:0)
在文档中是否有一些令人困惑的东西: MySQL Reference: Arithmetic Functions?
SELECT registration.hosteladmissionno,
## ...
messexp.billmonth,messexp.billyear ,messexp.perdayrate,student_month.days_mess
## additionally generated column:
messexp.perdayrate * student_month.day_mess AS account_payable
## ... end additionally generated column
FROM registration,student_month,messexp,blockexp student_month.hosteladmissionno = registration.hosteladmissionno
答案 3 :(得分:0)
SELECT (student_month.days_mess * anotehr_field ), registration.hosteladmissionno,
registration.student_name,
registration.semester,
student_month.hosteladmissionno,
student_month.student_name,
student_month.semester,
messexp.billmonth,messexp.billyear ,messexp.perdayrate,student_month.days_mess
FROM registration,
student_month ,messexp,blockexp
WHERE student_month.hosteladmissionno = registration.hosteladmissionno
;