简体   繁体   中英

How to add a SELECT statement result?

I have a DB with which I am running the below command. The aim is to show the HOURS field from each ROW where the DATE is equal to 02/08/2013. What I then want to do it to add the results and display as a total amount.

SELECT HOURS FROM RESOURCE WHERE DATE = '02/08/2013';

Current the results is 20 40 18. What I want is to output the total 78.

I have tried the below, but that just counts the results, 3.

SELECT COUNT(HOURS) FROM RESOURCE WHERE DATE = '02/08/2013'

Any suggestions are appreciated.

You can use,

SELECT SUM(HOURS) FROM RESOURCE WHERE DATE = '02/08/2013';

SQL FIDDLE OUTPUT

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