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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:44:59+00:00 2026-06-02T17:44:59+00:00

I have an order table like this ID OrderNumber Item Quantity Subtotal OrderedBy 1

  • 0

I have an order table like this


ID   OrderNumber        Item           Quantity        Subtotal     OrderedBy

1    2012-0001-12       Barbie            1              10         Thomas
2    2012-0001-12       Ken               2              20         Thomas
3    2012-0001-23       Mickie            4              28         Thomas
4    2012-0001-23       Minnie            3              21         Thomas
5    2012-0002-12       Barbie            1              10         Peter
6    2012-0003-01       Cake              1              12         Thomas
7    2012-0003-02       Wine              1              70         Thomas

In the OrderNumber the first two parts, that is for the first row 2012-001, is the actual order id.
The last part appended is the SupplierID which is not relevant in this case.

So this table now has three Orders


OrderNumber        OrderCount          Total        OrderedBy

2012-0001              4                 79          Thomas
2012-0002              1                 10          Peter
2012-0003              2                 82          Thomas

Currently I am looping through the DataTable after SELECTing everything from database and adding it to another generic list when 2012-0001 changes to 2012-0002. Meanwhile I am also adding the itemCount and total in the loop.

Is there a way to get the orders in a table(sql) or as an enumerable collection(linq) without this much hassle?

  • 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-02T17:45:00+00:00Added an answer on June 2, 2026 at 5:45 pm

    If you are just looking to create your second table, then you could try the following:

    SELECT SUBSTRING(OrderNumber, 1, 9) AS OrderNumber
        , COUNT(*) AS OrderCount
        , SUM(Subtotal) AS Total
        , OrderedBy
    FROM [Table]
    GROUP BY SUBSTRING(OrderNumber, 1, 9), OrderedBy
    

    This makes the assumption that a single order will always be done by the same person.

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

Sidebar

Related Questions

I am writing a turbogears2 application. I have a table like this: class Order(DeclarativeBase):
I have a MySQL query like this SELECT id,seq,text FROM table ORDER BY seq
I have a product order table in mysql. It's like this: create table `order`
I have an Order table like this: ORDER_ID PRODUCT_ID 1 1230 1 1231 1
I have a table OrderDetail like this: ID OrderNumber LineItem Qty --------------------------- 1 10000
I have a table like this in SQL ( it is not in order
I have an orders table with a schema like this. CREATE TABLE orders (
I have a table like: I have to order the rows in function of
I have a table with some ice cream order data like so: id order_number
I have a pg table like this: CREATE TABLE order_status_history ( order_id integer NOT

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.