[英]MySQL, SUM the column of a table view
This question may be miss comprehended, what I have done is created a column with a column view (not a full table view). 这个问题可能是我无法理解的,我所做的是创建带有列视图(而不是全表视图)的列。
For example: 例如:
SELECT SQL_CALC_FOUND_ROWS <Field1>, <Field2>, <Field3>, Hour(TIMEDIFF(<Field2>, <Field3>)) as <Field4> FROM <TableName>
The fourth field ( <Field4>
) with the time diff does not get sent to the database. 带有时间差异的第四个字段(
<Field4>
)不会发送到数据库。
Now what I want to do is use the sum formula on <Field4>
, but I am unsure on how to do this without it being saved to the database. 现在我想做的是使用
<Field4>
上的sum公式,但是我不确定如何在不将其保存到数据库的情况下执行此操作。
Any Ideas? 有任何想法吗?
EDIT: 编辑:
SELECT SQL_CALC_FOUND_ROWS Date, Start, Finish, Hour(TIMEDIFF(Start, Finish)) as HoursTest FROM Hours
Here is my actual select statement. 这是我的实际选择语句。
If I understand the question correctly, I think you want to save the select statement as a view, then do the sum from the view. 如果我正确理解了这个问题,我认为您想将select语句另存为视图,然后从视图中求和。
so 所以
create view mynewviewname as 创建视图mynewviewname为
SELECT SQL_CALC_FOUND_ROWS , , , Hour(TIMEDIFF(, )) as FROM SELECT SQL_CALC_FOUND_ROWS,,,Hour(TIMEDIFF(,))作为FROM
then 然后
SELECT sum(field4) from mynewviewname where (whatever you want to query by) 从mynewviewname的位置选择sum(field4)(无论您要查询什么)
Does that help? 有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.