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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:39:36+00:00 2026-05-22T14:39:36+00:00

Since it is a weird question, i couldn’t find the right answer. I am

  • 0

Since it is a weird question, i couldn’t find the right answer. I am developing an intranet for my company using codeigniter. I have a query syntax that lets me get all products in a given day:

$query = $this->db
         ->select('
             stock_meta.code_company AS product,
             stock_meta.company AS company,
             stock_meta.factory AS factory,
             COUNT(production.product) AS total_product
             ')
         ->from('production')
         ->join('stock_meta', 'production.product = stock_meta.code_local', 'inner')
         ->where('date BETWEEN ' . $start_date . ' AND ' . $end_date)
         ->group_by('product')
         ->order_by('factory')
         ->get();

and here it is syntax as MySQL:

SELECT
    stock_meta.code_company AS product,
    stock_meta.company AS company,
    stock_meta.factory AS total_product
FROM
    production
INNER JOIN
    stock_meta ON production.product = stock_meta.code_local
WHERE
    date BETWEEN 1304208650 AND 1304280234
GROUP BY
    product
ORDER BY
    factory

I am calling this query for just once.

I am getting result like this:

| product  | company  | factory  | total_product  |
+----------+----------+----------+----------------+
| 231234   | A        | Fac1     | 475            |
| 245214   | A        | Fac2     | 246            |
+----------+----------+----------+----------------+

And it works perfectly well. But I need to get the production between work shifts. there is tree work shifts: 00:00 – 08:00, 08:00 – 16:00, 16:00 – 24:00. How can I get work shifts for each product?

I mean I need to get result like this:

| product  | company  | factory  | shift1  | shift2  | shift3  | total_product  |
+----------+----------+----------+---------+---------+---------+----------------+
| 231234   | A        | Fac1     | 100     | 200     | 175     | 475            |
| 245214   | A        | Fac2     | 46      | 50      | 150     | 246            |
| 500231   | B        | aFaca1   | 46      | 50      | 150     | 246            |
+----------+----------+----------+---------+---------+---------+----------------+

And my Tables like this:

CREATE TABLE IF NOT EXISTS `production` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `factory` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
  `date` int(11) DEFAULT NULL,
  `operator` int(11) DEFAULT NULL,
  `product` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

CREATE TABLE IF NOT EXISTS `stock_meta` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code_local` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
  `code_company` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `company` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
  `factory` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `status` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=242 ;

So. Any idea?

Edit: I forget to mention it. I am using Unix timestamp.

Thank you for advice.

Best Redgards.

Gokhan

  • 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-22T14:39:37+00:00Added an answer on May 22, 2026 at 2:39 pm

    I’m tired and shouldn’t be writing code anymore. I’d think it would look like this though.

    SELECT
       stock_meta.code_company AS product,
       stock_meta.company AS company,
       stock_meta.factory AS total_product,
       s1.shift1,
       s2.shift2,
       s2.shift3,
       stock_meta.factory AS total_product
    FROM
       production
    INNER JOIN
       stock_meta ON production.product = stock_meta.code_local
    LEFT JOIN 
       ( SELECT stock_meta.code_company AS product, 
            COUNT(production.product) AS shift1
         FROM production, stock_meta
         WHERE production.product = stock_meta.code_local
         AND date BETWEEN '.$start_date.' AND '.strtotime('+8 hour', $start_date).'
       ) as s1 USING (product)
    LEFT JOIN 
       ( SELECT stock_meta.code_company AS product, 
            COUNT(production.product) AS shift2
         FROM production, stock_meta
         WHERE production.product = stock_meta.code_local
         AND date BETWEEN '.strtotime('+8 hour', $start_date).' AND '.strtotime('+16 hour', $start_date).'
       ) as s3 USING (product)
    LEFT JOIN 
       ( SELECT stock_meta.code_company AS product, 
           COUNT(production.product) AS shift3
         FROM production, stock_meta
         WHERE production.product = stock_meta.code_local
         AND date BETWEEN '.strtotime('+16 hour', $start_date).' AND '.strtotime('+24 hour', $start_date).'
       ) as s3 USING (product)
    WHERE
       date BETWEEN '.$start_date.' AND '.strtotime('+16 hour', $start_date).'
    GROUP BY
       product
    ORDER BY
       total_product
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question is going to be...weird and...odd. I have programmed stuffs for
Following this question: Weird MIPS assembler behavior with jump (and link) instruction I have
Its extremely weird since the program is iterating the file! outfolder and infolder are
Since CS3 doesn't have a web service component, as previous versions had, is there
OK, I realize that question might seem weird, but I just noticed something that
This might be a weird question, but I'll try anyway. I set up my
Having a weird issue. I'm new to Macs and have a windows VM that
I'm an working on a question where I have 10 keys and I have
I have run into a rather weird little problem. In the following code I
This is kind of a weird question. I'd like to write a Java function

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.