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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:06:47+00:00 2026-06-12T22:06:47+00:00

SELECT d_main.Type,ItemGrade,ItmName,d_sub.ItmCode, (CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type=’E’ THEN sum(d_sub.Qty) ELSE 0 END) as f1,

  • 0
SELECT d_main.Type,ItemGrade,ItmName,d_sub.ItmCode,
       (CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='E' 
             THEN sum(d_sub.Qty)  ELSE 0 END) as f1,
       (CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='L' 
             THEN  sum(d_sub.Qty)  ELSE 0 END) as f2
from d_main, d_sub, item
where d_main.FullNo=d_sub.FullNo and
      item.ItmCode = d_sub.ItmCode
group by d_main.Type,d_sub.ItmCode;

output

d_main.Type ItemGrade       ItmName d_sub.ItmCode   f1      f2  
----------- ---------       ------- -------------   --      --
E           A               AAAAAA  A005            5.000   0
E           B               BBBBBB  B006            1.000   0
E           C               CCCCCC  C015            3.050   0
L           A               AAAAAA  A005            0       5.750
L           B               BBBBBB  B006            0       8.000

expected result and answer that i want

    A       AAAAAA      A005        5.000   5.750
    B       BBBBBB      B006        1.000   8.000
    C       CCCCCC      C015        3.050   0.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-06-12T22:06:49+00:00Added an answer on June 12, 2026 at 10:06 pm

    Stop grouping on d_main.type, and sum your conditional items (instead of a conditional sum):

    SELECT ItemGrade, ItmName, d_sub.ItmCode,
           sum(CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='E' 
                    THEN d_sub.Qty ELSE 0 END) as f1,
           sum(CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='L' 
                    THEN d_sub.Qty ELSE 0 END) as f2
    from d_main, d_sub, item
    where d_main.FullNo=d_sub.FullNo and
          item.ItmCode = d_sub.ItmCode
    group d_sub.ItmCode;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to prevent sum(f)=0 from insert? INSERT INTO `t_1` (a,b,c) SELECT d,e,sum(f) GROUP by
THis is my project , i have to select the section , then acording
I am working on a project, which requires me to select a item from
I have the following LINQ Select which does not work. Data.Select(d => d.Value.IsDirty =
I have a select that I'd like to use the custom menu display (rather
So lets say i have a query like this SELECT a as d,b,c FROM
I'd like to select all rows from one table which match one or more
I'd like 3 SELECT boxes that allow people to select the month, day, and
I'd like a SELECT query to return specific value if the count of a
I'd like to call the Select function on the TextBox used by the SL3

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.