SELECT sum(" /> SELECT sum(" /> SELECT sum("/>

<cfoutput> a MySQL SUM function

90 views Asked by At

I understand the SQL sum function. This is the code I have:

<cfquery name="sum" datasource="expense_db" username = "for" password = "bar">
  SELECT sum(amount) 
  FROM expense
</cfquery> 

How do I output the result of the query? I just want to output the SUM of the amount column

1

There are 1 answers

1
rrk On

You can use an alias name for the column and use that column name in the Coldfusion code.

https://www.w3schools.com/sql/sql_alias.asp

<cfquery name="sum" datasource="expense_db" username = "for" password = "bar">
  SELECT sum(amount) AS Total 
  FROM expense
</cfquery> 

<cfoutput>#sum.Total#</cfoutput><!--- query_name.column_name --->