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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:27:51+00:00 2026-06-05T23:27:51+00:00

I have the following data from 2 tables Notes (left) and scans (right) :

  • 0

I have the following data from 2 tables Notes (left) and scans (right) :

enter image description here

Imagine the picker and packers were all varying, like you can have JOHN, JANE etc.

I need a query that outputs like so :

On a given date range :

Name - Picked (units) - Packed (units)
MASI - 15 - 21
JOHN - 21 - 32

etc.

I can’t figure out how to even start this, any tips will be helpful thanks.

  • 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-05T23:27:53+00:00Added an answer on June 5, 2026 at 11:27 pm

    Without a “worker” take that lists each Picker/Packer individually, I think you’d need something like this…

    SELECT
          CASE WHEN action.name = 'Picker' THEN scans.Picker ELSE scans.Packer END  AS worker,
      SUM(CASE WHEN action.name = 'Picker' THEN notes.Units  ELSE 0            END) AS PickedUnits,
      SUM(CASE WHEN action.name = 'Packer' THEN notes.Units  ELSE 0            END) AS PackedUnits
    FROM
      notes
    INNER JOIN
      scans
        ON scans.PickNote = notes.Number
    CROSS JOIN
    (
                SELECT 'Picker' AS name
      UNION ALL SELECT 'Packer' AS name
    
    )
      AS action
    GROUP BY
      CASE WHEN action.name = 'Picker' THEN scans.Picker ELSE scans.Packer END
    

    (This is actually just an algebraic re-arrangement of the answer that @RaphaëlAlthaus posted at the same time as me. Both use UNION to work out the Picker values and the Packer values separately. If you have separate indexes on scans.Picker and scans.Packer then I would expect mine MAY be slowest. If you don’t have those two indexes then I would expect mine to be fastest. I recommend creating the indexes and testing on a realtisic data set.)

    EDIT

    Actually, what I would recommend is a change to scans table completely; normalise it.

    • Your de-normalised set has one row per PickNote, with fields picker and packer.
    • A normalised set would have two rows per PickNote with fields role and worker.

      id  | PickNote | Role | Worker
    ------+----------+------+--------
      01  | PK162675 | Pick |  MASI
      02  | PK162675 | Pack |  MASI
      03  | PK162676 | Pick |  FRED
      04  | PK162676 | Pack |  JOHN
    

    This allows you to create simple indexes and simple queries.

    You may initially baulk at the extra unecessary rows, but it will yield simpler queries, faster queries, better maintainability, increased flexibility, etc, etc.

    In short, this normalisation may cost a little extra space, but it pays back dividends forever.

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

Sidebar

Related Questions

I have the following sample of data to insert into tables(from parent to child,
I have the following linq expression pulling all data from my database: var items
I have table that I insert data with following query (from c# code): INSERT
I have the following two methods for getting data from my database: - (void)
I have the following code in my application to load some data from my
I have the following situation: I have an application that collects some data from
I have the following situation. Im getting data from an external system in the
In general, I have the following scenario: Fetch product and its related data from
I have to build a tree using the following data which comes from a
I have tables & data like this: venues table contains : id +----+---------+ |

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.