Anthony Ehrhardt
Anthony Ehrhardt

Reputation: 11

<cfoutput> a MySQL SUM function

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

Upvotes: 0

Views: 95

Answers (1)

rrk
rrk

Reputation: 15846

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 --->

Upvotes: 9

Related Questions