Skip to main content
Dani Szwarc
Inspiring
April 4, 2008
Question

Building a complex cfquery

  • April 4, 2008
  • 4 replies
  • 595 views
Hello community. I'm building an application and I'm getting a bit lost when building the logic for a report:

This is for a construction company. Everyday the enter the information of what was done that day and how much money in material, rental and labour they spent. At the same time, this is entered by category and subcategory. So let's say my 3 (I want them to enter the info in different forms) forms say:

Choose Category:
Choose subcategory:
Material:
Amount spent:

Form for labour:

Choose Category:
Choose subcategory:
Worker:
Worked hours:

and for rental:

Choose Category:
Choose subcategory:
Rental:
Amount spent:

Whatever they enter goes to the same table "control", to the proper fields projectID, catID, subID, matID, matExpenses, workerID, workedHours (worker wage is from a different table), rentID, rentExpenses.

So let's say they want to see how much money they spent in the category "Concrete" (which has many subcategories), they select that from the form and the report should show the following:

Category: Concrete

Subcategory: Sub1
Material for Sub1: 300
Labour for Sub1: 6000
Rentals for Sub1: 200
Sub1 Subtotal: 6500

Subcategory: Sub2
Material for Sub2: 800
Labour for Sub2: 5000
Rentals for Sub2: 200
Sub2 Subtotal: 6000

And son on

I'm getting lost with the query. How do I do to display the money spent per item (material, labour and rental) per subcategory?

Thanks in advance.
    This topic has been closed for replies.

    4 replies

    Inspiring
    April 7, 2008
    Give sum(results) an alias if you want to display it.
    Dani Szwarc
    Inspiring
    April 7, 2008
    Etienne and Dan, thanks so much for your answers!!! I was able to solve it in a different way, but I'm not sure is the best one. It does what I want.

    I like Etienne your query, it makes sense...I didn't try it yet. A question about it: How do you show the SUM results?

    Thanks again to both of you
    Participating Frequently
    April 7, 2008
    What about :

    SELECT subID, SUM(matExpenses), SUM(workedHours), SUM(rentExpenses)
    FROM control
    WHERE catID = 'Concrete' (or the ID of the category)
    GROUP BY subID

    Etienne
    Inspiring
    April 4, 2008
    This thread should give you some insight.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=3&threadid=1351217&enterthread=y

    Pay particular attention to the comments about sorting the query (aka order by clause)