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 7591577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:41:09+00:00 2026-05-30T20:41:09+00:00

Quick question if anyone has time to answer. The current query works great, but

  • 0

Quick question if anyone has time to answer. The current query works great, but I need to also get a total count of the orders and the total shipping. I know the numbers are getting thrown off because of the joins.

I know that my count and sum will be:

count(DISTINCT orders.id) AS num_orders,
SUM(orders.shipping_cost_ex_tax) AS shipping

I think I need to use the count and sum in the original select and handle the rest in the join, but for the life of me I can’t get this right.

Any help would be appreciated, even if it’s “run a separate query”. Thanks everyone.

Current query:

SELECT 
    IF(products.categories LIKE '68', 'Shirts', 'Books') AS group_key,
    CONCAT(order_products.name) AS product_name,
    brands.name AS author,
    SUM(order_products.quantity) AS num_units,
    CASE WHEN products.sku LIKE '%-WB' THEN 'Combo'
        WHEN products.sku LIKE '%-BO' THEN 'Box'
        ELSE ''
    END AS item_type,
    SUM(IF(order_products.discount IS NULL, order_products.price_ex_tax, (order_products.price_ex_tax - order_products.discount))) AS income 
 FROM orders 
 INNER JOIN order_products ON order_products.bc_order_id = orders.bc_id
 INNER JOIN products ON order_products.bc_product_id = products.bc_id
 INNER JOIN brands ON products.brand_id = brands.bc_id 
 WHERE (orders.created_at BETWEEN '2012-01-28 00:00:00' and '2012-02-21 23:00:00') 
 GROUP BY group_key,
 case when products.brand_id = '68'
 then products.name
 else products.sku
 end
  • 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-05-30T20:41:10+00:00Added an answer on May 30, 2026 at 8:41 pm

    Looking at the comment provided and not having your full schema in front of me. Would something like this work:

    Table Report  
    (  
        id,  
        countOrders,  
        countSales,  
        countShipping,  
        countTax,  
        datePublished  
    )   
    
    Table SoldProducts  
    (  
        id,  
        price,    
        tax,  
        shippingPrice,  
        datePurchased  
    )  
    

    So what you would do in this instance is generate a report by querying from SoldProducts then you would persist the report that was generated.

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

Sidebar

Related Questions

Hey just a quick question for anyone who has done this. I want to
I hope this question has an obvious answer to anyone who knows his way
Just a quick question, does anyone know if there are restrictions on creating Performance
Hey guys I have a quick question, I have a dialog box that has
Quick Question: Anyone knows this? : http://lwis.net/free-css-drop-down-menu/ It uses javascript for -IE6 only, but
I am sure this is as simple as a question can get but I
Quick question, could anyone help me out with regards to writing this without dot
Quick bash/terminal question - I work a lot on the command line, but have
quick question really that has me momentarily stumped. This program searches through a a
Quick question. Does anyone know if there is a way you can disable the

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.