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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:59:46+00:00 2026-06-15T02:59:46+00:00

I have a table OrderID Qty ShopID ———————– 1 50 10 1 50 11

  • 0

I have a table

OrderID   Qty    ShopID
-----------------------
1         50     10
1         50     11
2         10     15
2         10     18

The person ordered the same order at different shops (they will later decide which one will supply it), but I must only show one qty per order, please help setting the qty = 0 where the orderid is the same and shopid > min(shopID)

e.g.

OrderID   Qty    ShopID
-----------------------
1         50     10
1         0      11
2         10     15
2         0      18 

This is just an example of the real world problem pls

  • 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-15T02:59:47+00:00Added an answer on June 15, 2026 at 2:59 am

    You can try something like this:

    ;WITH CTE AS
    (
        SELECT 
            OrderID, Qty, ShopID,
            RowNum = ROW_NUMBER() OVER (PARTITION BY OrderID ORDER BY ShopID DESC)
        FROM
            dbo.YourOrderTableHere
    )
    SELECT
        OrderID,
        OrderedQty = CASE RowNum    
                        WHEN 1 THEN Qty ELSE 0 
                     END,
        ShopID
    FROM CTE    
    

    Basically, I “partition” the data by OrderID – so each row within a given order gets assigned a consecutive RowNum.

    In the select from the CTE (Common Table Expression), I return the quantity as stored in the table for the order with RowNum = 1, and I suppress that quantity and return 0 instead for all additional rows for that same OrderID.

    This gives me an output of:

    enter image description here

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

Sidebar

Related Questions

I have 2 tables Order Table - OrderId- Primary key Order Details Table -
I have the following Table named Order Orders Table ___________________________________________________ orderiD | userId |
I have order table OrderId OrderStatusId CurrencyId PromotionCode ------------------------------------------------------ 137 5 1 123a-123d 138
I have 2 table. Table1 Order orderid - customer_id 1001 - 1234 Table2 Items
I have a table with the fields: orderID collection delivery username collection and delivery
If I have a table Orders with fields CustomerID , OrderID and OrderDate ,
I have a table 'results' in which the scores are stored. Its ordered by
I have a table: custID orderID orderComponent ===================================== 1 123 pizza 1 123 wings
I have these two tables Orders and Employees Orders Table OrderID EmployeeID 1 1
i have a table with order details. User is able to modify these details

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.