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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:21:41+00:00 2026-05-22T12:21:41+00:00

I have a query that outputs address order data: SELECT ordernumber , article_description ,

  • 0

I have a query that outputs address order data:

SELECT ordernumber
  , article_description
  , article_size_description
  , concat(NumberPerBox,' pieces') as contents
  , NumberOrdered
FROM customerorder
WHERE customerorder.id = 1;

I would like the above line to be outputted NumberOrders (e.g. 50,000) divided by NumberPerBox e.g. 2,000 = 25 times.

Is there a SQL query that can do this, I’m not against using temporary tables to join against if that’s what it takes.

I checked out the previous questions, however the nearest one:
is to be posible in mysql repeat the same result
Only gave answers that give a fixed number of rows, and I need it to be dynamic depending on the value of (NumberOrdered div NumberPerBox).

The result I want is:

Boxnr   Ordernr        as_description   contents   NumberOrdered
------+--------------+----------------+-----------+---------------
  1   | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
  2   | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
....
  25  | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
  • 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-22T12:21:41+00:00Added an answer on May 22, 2026 at 12:21 pm

    First, let me say that I am more familiar with SQL Server so my answer has a bit of a bias.
    Second, I did not test my code sample and it should probably be used as a reference point to start from.

    It would appear to me that this situation is a prime candidate for a numbers table. Simply put, it is a table (usually called “Numbers”) that is nothing more than a single PK column of integers from 1 to n. Once you’ve used a Numbers table and aware of how it’s used, you’ll start finding many uses for it – such as querying for time intervals, string splitting, etc.

    That said, here is my untested response to your question:

    SELECT
       IV.number as Boxnr
      ,ordernumber  
      ,article_description
      ,article_size_description
      ,concat(NumberPerBox,' pieces') as contents
      ,NumberOrdered
    FROM
      customerorder
      INNER JOIN (
        SELECT
           Numbers.number
          ,customerorder.ordernumber
          ,customerorder.NumberPerBox
        FROM
          Numbers
          INNER JOIN customerorder
            ON Numbers.number BETWEEN 1 AND customerorder.NumberOrdered / customerorder.NumberPerBox
        WHERE
          customerorder.id = 1
        ) AS IV
        ON customerorder.ordernumber = IV.ordernumber
    

    As I said, most of my experience is in SQL Server. I reference http://www.sqlservercentral.com/articles/Advanced+Querying/2547/ (registration required). However, there appears to be quite a few resources available when I search for “SQL numbers table”.

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

Sidebar

Related Questions

I have a query that looks like this: SELECT SUM(`georder`) AS `order`, SUM(quantity) AS
I have a query that uses the outputs(R1,R2) of two sub queries in order
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
So I have a sql server 2005 query that returns results like so: Address
I have a query that outputs results as follows: Person Food ====== ====== Abner
I have a SQL query that outputs a bunch of rows that match a
I have the following query that outputs the users that received the highest number
I have an sqlite query that looks like this: db_rows = db_cursor.execute( SELECT *
I have a query that is dynamically built after looking up a field list
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)

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.