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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:06:05+00:00 2026-05-17T18:06:05+00:00

I am wondering if there is a way to optimize this query: SELECT Avg(selloff1),

  • 0

I am wondering if there is a way to optimize this query:

SELECT Avg(selloff1), 
       YEAR(dt), 
       weekno 
FROM   bbproduct 
GROUP  BY YEAR(dt), 
          weekno 

Table schema is:

CREATE TABLE `bbproduct` (
 `id` bigint(20) NOT NULL,
 `CUSTNO` decimal(6,0) unsigned zerofill NOT NULL default '000000',
 `DEPTNO` decimal(1,0) unsigned zerofill NOT NULL default '0',
 `PRODNO` decimal(4,0) unsigned zerofill NOT NULL default '0000',
 `DT` date NOT NULL,
 `ARDATE8N` decimal(8,0) unsigned zerofill NOT NULL default '00000000',
 `STORENO` char(6) NOT NULL default '0',
 `DAYCODE` decimal(1,0) unsigned zerofill NOT NULL default '0',
 `WEEKNO` decimal(2,0) unsigned zerofill NOT NULL default '00',
 `WKOFMONTH` decimal(2,0) unsigned zerofill NOT NULL default '00',
 `QUANTITY` decimal(7,0) NOT NULL default '0',
 `CARRYOVER` decimal(7,0) NOT NULL default '0',
 `SELLOFF1` decimal(7,0) NOT NULL default '0',
 `ONHANDQTY` decimal(7,0) NOT NULL default '0',
 `KNOWNLOSS` decimal(7,0) NOT NULL default '0',
 `ORDER` decimal(7,0) NOT NULL default '0',
 `FAMLYCD` decimal(4,0) NOT NULL default '0',
 `ROUTENO` decimal(4,0) NOT NULL default '0',
 `AGENCYNO3N` decimal(3,0) NOT NULL default '0',
 `RETURNS` decimal(7,0) NOT NULL,
 `LASTUPDATE` datetime NOT NULL,
 PRIMARY KEY  (`CUSTNO`,`DEPTNO`,`PRODNO`,`DT`),
 KEY `in_bbproduct_custnodeptnoprodno` (`CUSTNO`,`DEPTNO`,`PRODNO`),
 KEY `in_bbproduct_deptnocustno` USING BTREE (`DEPTNO`,`CUSTNO`),
 KEY `in_bbproduct_custno` USING BTREE (`CUSTNO`),
 KEY `in_bbproduct_dt` USING BTREE (`DT`),
 KEY `in_bbproduct_routeno` (`ROUTENO`),
 KEY `in_bbproduct_selloff1` (`SELLOFF1`),
 KEY `in_bbproduct_weekno` (`WEEKNO`),
 KEY `in_bbproduct_routenoweekno` (`WEEKNO`,`ROUTENO`),
 KEY `in_bbproduct_agencyroutedt` USING BTREE (`AGENCYNO3N`,`ROUTENO`,`DT`),
 KEY `in_bbproduct_routenoagencyno3n` (`ROUTENO`,`AGENCYNO3N`),
 KEY `in_bbproduct_agencyno` (`AGENCYNO3N`),
 KEY `in_bbproduct_storeno_prodno` (`STORENO`,`PRODNO`),
 KEY `ind_deptno_prodno` (`DEPTNO`,`PRODNO`),
 KEY `ind_prodno` (`PRODNO`),
 KEY `ind_dt_custno_deptno_prodno` (`DT`,`CUSTNO`,`DEPTNO`,`PRODNO`),
 KEY `ind_dt_selloff1` (`DT`,`SELLOFF1`)
) ENGINE=MyISAM AUTO_INCREMENT=9300871 DEFAULT CHARSET=latin1

It takes 14 seconds, table has 9 millions of records, and query returns 15 rows. I will need to join this result set with some other records.

Can I do something more?

  • 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-17T18:06:06+00:00Added an answer on May 17, 2026 at 6:06 pm

    Since you are grouping by year and week number, I presume that most of the data will not change more than weekly. You can cache the result in another table that can be updated in batch only one time per week.

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

Sidebar

Related Questions

I'm wondering if there's any way to optimize the following SELECT query. (Note: I
Wondering if there is any way to get the lambda expressions that result from
Just wondering is there any way I can check whether the url links to
I was wondering is there a way to give the user a small guided
I was wondering is there a way in visual studio 2010 to search in
I was wondering is there a way in PHP that you could tell where
I am wondering is there a way to render a partial view in the
I am wondering is there any way we can test the font size/color of
I am wondering is there any way to execute following shell script, which waits
just wondering if there is a way to reduce the amount of code needed

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.