Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:22:21+00:00 2026-06-14T10:22:21+00:00

I have a query: <cfquery name=getDesc datasource=#ds#> SELECT desc, SUM(charge) as cost, COUNT(*) as

  • 0

I have a query:

<cfquery name="getDesc" datasource="#ds#">
  SELECT
    desc,
    SUM(charge) as cost,
    COUNT(*) as cnt
  FROM
    product
  WHERE Length(desc) > 0
</cfquery>

Which then populates a table:

<table>
  <tbody>
      <tr>
        <th>Description</th>
        <th>Amount of Charges</th>
        <th>Cost (&pound;)</th>
      </tr>

      <cfoutput query="getDesc">
      <tr>
        <td>
          #HTMLEditFormat(getDesc.desc)# <br />
        </td>     
        <td>
          #HTMLEditFormat(getDesc.cnt)# <br />
        </td>
        <td>
            #HTMLEditFormat(getDesc.cost)# <br />
        </td>
      </tr>
    </cfoutput>
  </tbody>
</table>

My problem is that I’d like to combine two rows of the table that have the same value and also have both of their counts added together.

So far I have:

<table>
  <tbody>
      <tr>
        <th>Description</th>
        <th>Amount of Charges</th>
        <th>Cost (&pound;)</th>
      </tr>

      <cfoutput query="getDesc">
      <tr>
        <cfif getDesc.desc EQ 'No Charge' OR getDesc.desc EQ 'No Charge (2)'>
          <td>
            No Charge & (2)
          </td>
          <td>
            <cfset cntSum = arraySum(getDesc['cnt'])>
            #cntSum#
          </td>
        <cfelse>
        <td>
          #HTMLEditFormat(getDesc.desc)# <br />
        </td>     
        <td>
          #HTMLEditFormat(getDesc.cnt)# <br />
        </td>
        </cfif>
        <td>
            #HTMLEditFormat(getDesc.cost)# <br />
        </td>
      </tr>
    </cfoutput>
  </tbody>
</table>

But this gives me two rows of ‘No Charge & (2)’ and the count is the sum of all the rest of the rows in the table rather than just the two rows I want.

Hope this makes sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:22:22+00:00Added an answer on June 14, 2026 at 10:22 am

    I would change your query around to get you the data you need. Here’s what I’ve just whipped up which I think would meet your requirement:

      SELECT
        CASE `desc` WHEN 'No Charge (2)' THEN 'No Charge' ELSE `desc` END,
        SUM(charge) as cost,
        COUNT(*) as cnt
      FROM
        product
      WHERE Length(`desc`) > 0
      group by CASE `desc` WHEN 'No Charge (2)' THEN 'No Charge' ELSE `desc` END
    

    The case statement is changing ‘No Charge (2)’ into ‘No Charge’ so there’s only one row for both kinds of values. The group by statement is making mySQL perform the sum and count once per different value of ‘desc’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two queries: <cfquery name=getChairReview datasource=#application.dsn#> SELECT* FROM eval_reviews WHERE faculty = <cfqueryparam
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have the following ColdFusion 9 code: <cfloop from=1 to=#arrayLen(tagArray)# index=i> <cfquery name=qryGetSPFAQs datasource=#application.datasource#>
Given a query (pseudo-code): <cfquery name=myquery>SELECT * FROM stuff</cfquery> How do I get rid
I have the following query where I combine two fields from two tables: <cfquery
I have query like this SELECT AVAILABILITY_DATE_TIME FROM APPT_PROVIDER_AVAILABILITY WHERE AVAILABILITY_DATE_TIME between @START_DATE AND
I have a query similar to this: SELECT itemID FROM itemTable WHERE itemID LIKE
I have a query that successfully grabs the unique products from my products table
I am trying to build a cfquery using a dynamic column name: <cfquery dbtype=query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.