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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:05:43+00:00 2026-06-09T17:05:43+00:00

I see there is an error in the last line. Can someone please tell

  • 0

I see there is an error in the last line. Can someone please tell me what is the alternative?

INSERT INTO month_week_qty 
(
    site_id, cat_id, cat_name, scat_id, scat_name, sscat_id, sscat_name, duration, w_m, year, sum_qty
) 
SELECT 
    c.site_id, NULL, NULL, NULL, NULL, NULL, NULL, 'month', MONTH(s.created_at), YEAR(s.created_at), ROUND( SUM( s.qty_ordered ) ) as qty 
FROM cat_products c, sku_qty_brand s
WHERE (c.product_id = s.product_id)
GROUP BY c.site_id, MONTH(s.created_at)
ON DUPLICATE KEY UPDATE sum_qty = sum_qty + ROUND( SUM( s.qty_ordered ) )
  • 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-09T17:05:44+00:00Added an answer on June 9, 2026 at 5:05 pm

    You cannot use aggregates in the ON DUPLICATE KEY UPDATE clause, but you can put your grouped aggregates in a subquery instead:

    INSERT INTO month_week_qty 
    (
        site_id, duration, w_m, year, sum_qty
    ) 
    SELECT 
        site_id, duration, w_m, year, qty
    FROM (
        SELECT 
            c.site_id, 'month' AS duration, MONTH(s.created_at) AS w_m, YEAR(s.created_at) AS year, ROUND( SUM( s.qty_ordered ) ) as qty 
        FROM cat_products c, sku_qty_brand s
        WHERE (c.product_id = s.product_id)
        GROUP BY c.site_id, MONTH(s.created_at)
    ) AS t
    ON DUPLICATE KEY UPDATE sum_qty = sum_qty + t.qty
    

    (I omitted the NULL columns for clarity.)

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

Sidebar

Related Questions

I get this error all the time. And as I can see, there are
There's an error message I can't understand since I don't see where my code
I hope someone here can help me see where this error is coming from.
I'm getting error: Unrecognised selector sent to instance, upon inspection, I see there is
I see there is version 1.5 and 3.0 beta , but I can't seem
I see there are techniques available to have deep models in Backbone, but how
I see there are several posts regarding Cannot set Property and I'm still struggling
I see there is a question here but there is no definite answer. Has
I see there are BN_CLICKED and BN_DBLCLK notification messages for a button control. but
I see there are lot's of examples in Ext JS where instead of actually

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.