简体   繁体   中英

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.

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.

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.

so

create view mynewviewname as

SELECT SQL_CALC_FOUND_ROWS , , , Hour(TIMEDIFF(, )) as FROM

then

SELECT sum(field4) from mynewviewname where (whatever you want to query by)

Does that help?

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