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

  • SEARCH
  • Home
  • 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 8524427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:41:01+00:00 2026-06-11T07:41:01+00:00

been struggling with this all day now trying various combos without any joy if

  • 0

been struggling with this all day now trying various combos without any joy if anyone can help? I use WITH ROLLUP to sum a Total column which adds a row to foot of table outputting each columns sum.

I now need to order the last column [profits] descending so highest number is at top. I have achieved this using query below but it also sorts the ROLLUP row, is there a method to have the rollup as a separate entity so the ORDER BY is only done on normal records?

Select
  *
From
  (Select
      c.ContactFullName As Adviser,
      Sum(If(Month(b.CaseDate) = 1, b.LeadCost, 0)) As Jan,
      Sum(If(Month(b.CaseDate) = 2, b.LeadCost, 0)) As Feb,
      Sum(If(Month(b.CaseDate) = 3, b.LeadCost, 0)) As Mar,
      Sum(If(Month(b.CaseDate) = 4, b.LeadCost, 0)) As Apr,
      Sum(If(Month(b.CaseDate) = 5, b.LeadCost, 0)) As May,
      Sum(If(Month(b.CaseDate) = 6, b.LeadCost, 0)) As Jun,
      Sum(If(Month(b.CaseDate) = 7, b.LeadCost, 0)) As Jul,
      Sum(If(Month(b.CaseDate) = 8, b.LeadCost, 0)) As Aug,
      Sum(If(Month(b.CaseDate) = 9, b.LeadCost, 0)) As Sep,
      Sum(If(Month(b.CaseDate) = 10, b.LeadCost, 0)) As Oct,
      Sum(If(Month(b.CaseDate) = 11, b.LeadCost, 0)) As Nov,
      Sum(If(Month(b.CaseDate) = 12, b.LeadCost, 0)) As Decb,
      Sum(b.LeadCost) As LeadCosts,
      Sum(b.CaseCommission) As GrossComm,
      (Sum(b.CaseCommission) * 40 / 100) As GHL_Comm,
      (Sum(b.CaseCommission) * 40 / 100 - Sum(b.LeadCost)) As Profit
    From
      tblcontacts a Inner Join
      tblcases b On a.ContactID = b.ContactID Inner Join
      mi_tblcontacts c On c.Mi_ContactID = b.ContactAssignedTo Inner Join
      tblreferral d On d.RefferalID = a.ContactReferrelSource
    Group By
      c.ContactFullName With Rollup) q
Order By
  q.Profit Desc

Any help appreciated.

G

  • 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-11T07:41:03+00:00Added an answer on June 11, 2026 at 7:41 am

    You could try something like this:

    SELECT *, If(ContactFullName is null, 1, 0) as rolledup 
    FROM ( .... giant inner select goes here ...)
    ORDER BY rolledup asc, q.profit desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this for a while now so hopefully someone can help
I've been struggling with this issue for a while now. Maybe you can help.
I've been struggling with this all day. I am trying to add forms authentication
Have been struggling all day trying to make this simple example work using socket.io.
I have been struggling with this all day. I have an html table in
Okay, I've been struggling with this all weekend, and I've gotten plenty of help
Been struggling with this for quite some time so any help is appreciated. Spent
I've been struggling for this for a while now. I'm trying to gear up
Ive been struggling with this all day, been close a couple times but nothing
I have been struggling with this for the past few hours. All I'm trying

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.