To avoid putting a field in group by clause

hi all
i have the following query with me
SELECT   SUM (  (NVL (f.calc_cement_sk, f.calc_amount) * NVL (f.item_price, 0)
              - (  NVL (f.calc_cement_sk, f.calc_amount)
                 * NVL (f.item_price, 0)
                 * (NVL (f.dis_per, 0) / 100)
             ) total,
         h.slurry_type, h.stage_id, h.slurry_vol_actual
    FROM xxnp_opn_joblog_est_002 f,
         xxnp_opn_joblog_001 j,
         xxnp_opn_joblog_slurry_003 h,
         qp_secu_list_headers_v qw
   WHERE j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
     AND f.opn_joblog_001_id = j.opn_joblog_001_id
     AND j.contract = qw.NAME
     AND h.opn_joblog_001_id = j.opn_joblog_001_id
     AND h.opn_joblog_007_id = f.opn_joblog_007_id
     AND h.opn_joblog_006_id = f.opn_joblog_006_id
GROUP BY h.stage_id, h.slurry_type, h.slurry_vol_actualthe output i get is
TOTAL     SLURRY_TYPE     STAGE_ID     SLURRY_VOL_ACTUAL
9,562.59     Lead     1      490
2,184.84     Tail     1      80
1,091.73     Top Up     1      56
3,431.64     Tail     2      100
when i add f.item_number to the above query as shown below
SELECT   SUM (  (NVL (f.calc_cement_sk, f.calc_amount) * NVL (f.item_price, 0)
              - (  NVL (f.calc_cement_sk, f.calc_amount)
                 * NVL (f.item_price, 0)
                 * (NVL (f.dis_per, 0) / 100)
             ) total,f.item_number,
         h.slurry_type, h.stage_id, h.slurry_vol_actual
    FROM xxnp_opn_joblog_est_002 f,
         xxnp_opn_joblog_001 j,
         xxnp_opn_joblog_slurry_003 h,
         qp_secu_list_headers_v qw
   WHERE j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
     AND f.opn_joblog_001_id = j.opn_joblog_001_id
     AND j.contract = qw.NAME
     AND h.opn_joblog_001_id = j.opn_joblog_001_id
     AND h.opn_joblog_007_id = f.opn_joblog_007_id
     AND h.opn_joblog_006_id = f.opn_joblog_006_id
GROUP BY h.stage_id, h.slurry_type, h.slurry_vol_actual,f.item_number
the field total gets split and gives value corresponding to each item_number
i am giving the ouptut for stage 1TOTAL     ITEM_NUMBER     SLURRY_TYPE     STAGE_ID     SLURRY_VOL_ACTUAL
5011.5     1020101001     Lead      1     490
1308.93     1020102002     Lead      1     490
127.215     1020111001     Lead      1     490
138.92     1020112001     Lead      1     490
686     1020113001     Lead     1     490
550.5     1020113002     Lead 1     490
1739.52     1020222010     Lead      1     490
1517.1     1020101001     Tail     1     80
379.5     1020102003     Tail     1     80
83.2     1020103001      Tail     1     80
166.53     1020104001     Tail     1 80
38.511     1020111001     Tail     1     80
1064.7     1020101001     Top Up     1     56
27.027     1020111001     Top Up     1 56
if we sum values in total field corresponding to lead ,tail,top up we get 9562.59,2184.84,1091.73 respectively
kindly guide
to get total value as initial query even if item_number is added
thanking in advance
Edited by: makdutakdu on Jul 16, 2012 2:12 PM
Edited by: makdutakdu on Jul 16, 2012 2:14 PM
Edited by: makdutakdu on Jul 16, 2012 2:16 PM

hi
when i comment j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
this query returns value for all opn_job_desc and it gives incorrect value as h.slurry_type of lead ,tail ,top_up is there for all values of opn_job_desc
if i do partition by opn_job_desc i get sum of  5616.485
  1091.727 and 9562.585 ie 16270.797
with t
as
SELECT   SUM (  (NVL (f.calc_cement_sk, f.calc_amount) * NVL (f.item_price, 0)
              - (  NVL (f.calc_cement_sk, f.calc_amount)
                 * NVL (f.item_price, 0)
                 * (NVL (f.dis_per, 0) / 100)
             ) total,f.item_number,
         h.slurry_type, h.stage_id, h.slurry_vol_actual,j.opn_job_desc
    FROM xxnp_opn_joblog_est_002 f,
         xxnp_opn_joblog_001 j,
         xxnp_opn_joblog_slurry_003 h,
         qp_secu_list_headers_v qw
   WHERE --j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
     f.opn_joblog_001_id = j.opn_joblog_001_id
     AND j.contract = qw.NAME
     AND h.opn_joblog_001_id = j.opn_joblog_001_id
     AND h.opn_joblog_007_id = f.opn_joblog_007_id
     AND h.opn_joblog_006_id = f.opn_joblog_006_id
GROUP BY h.stage_id, h.slurry_type, h.slurry_vol_actual,f.item_number,j.opn_job_desc
select sum(total) over(partition by opn_job_desc) total, item_number, slurry_type, stage_id, slurry_vol_actual,opn_job_desc
  from tis there any way to include item_number in query but the total remains as such
kindly guide
thanking in advance
Edited by: makdutakdu on Jul 16, 2012 2:37 PM

Similar Messages

  • Select not working with Case unless adding field to group by clause

    Hi, I have a simple query that I am trying to run.  The first version runs, but I am trying to get the second version to run, because I do not want to have to include PAYRCORD in the Group By.  Since I do not want it grouped by PAYRCORD.
    Is there a way to write the second version to work?
    ---- First Version ---
    SELECT     TOP (100) PERCENT YEAR1, EMPLOYID, PAYRCORD,
    CASE WHEN (dbo.tw80507.PAYRCORD LIKE '%OT%' AND NOT (dbo.tw80507.PAYRCORD LIKE 'OTHER'))
                          THEN SUM(DISTINCT dbo.tw80507.TwOriginalTaxableWages) ELSE NULL END AS OT,
    CASE WHEN dbo.tw80507.PAYRCORD NOT LIKE '%OT%'
                          THEN SUM(DISTINCT dbo.tw80507.TwOriginalTaxableWages) ELSE NULL END AS REG
    FROM         dbo.TW80507
    GROUP BY YEAR1, EMPLOYID, PYRLRTYP, PAYRCORD
    HAVING      (YEAR1 > 2013) AND (PYRLRTYP = 3)
    ORDER BY YEAR1
    --- Second Version ---
    SELECT     TOP (100) PERCENT YEAR1, EMPLOYID,
    CASE WHEN (dbo.tw80507.PAYRCORD LIKE '%OT%' AND NOT (dbo.tw80507.PAYRCORD LIKE 'OTHER'))
                          THEN SUM(DISTINCT dbo.tw80507.TwOriginalTaxableWages) ELSE NULL END AS OT,
    CASE WHEN dbo.tw80507.PAYRCORD NOT LIKE '%OT%'
                          THEN SUM(DISTINCT dbo.tw80507.TwOriginalTaxableWages) ELSE NULL END AS REG
    FROM         dbo.TW80507
    GROUP BY YEAR1, EMPLOYID, PYRLRTYP
    HAVING      (YEAR1 > 2013) AND (PYRLRTYP = 3)
    ORDER BY YEAR1

    Put the CASE inside the SUM.
    I also cleaned up your query by removing an excess of prefixes, making the code difficult to read, and I replaced HAVING with WHERE. (You use HAVING WHEN you need to filter on an aggregate value, for instance HAVING COUNT(*) > 2.) Finally, I removed the
    DISTINCT from the SUM, because that looked, well, funny.
    SELECT  YEAR1, EMPLOYID,
             SUM(CASE WHEN PAYRCORD LIKE '%OT%' AND NOT (PAYRCORD LIKE 'OTHER')
                      THEN TwOriginalTaxableWages)
                      ELSE 0
                 END) AS OT,
            SUM(CASE WHEN PAYRCORD NOT LIKE '%OT%'
                     THEN TwOriginalTaxableWages
                     ELSE 0
                END AS) REG
    FROM    dbo.TW80507
    WHERE   YEAR1 > 2013
       AND  PYRLRTYP = 3
    GROUP BY YEAR1, EMPLOYID
    ORDER BY YEAR1
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Avoid Duplicate Tasks when Expanding Groups for Custom Task Process

    Is there a way to:
    Avoid Duplicate Tasks when Expanding Groups for Custom Task Process?
    I've got a people metadata column that I am planning on putting groups into.  I want the groups to expand and send a task for all users in the groups.  I also want to avoid creating multiple tasks if a user happens to be in two groups at the same
    time.
    I'm trying to work out a way to assign users a read task based on job training requirements.  Right now assigning groups and using a workflow task to confirm read is what I'm trying to accomplish.  I just end up getting two tasks for a user if
    their in multiple groups.
    David Jenkins

    Hi David,
    Please verify the followings:
    After Participants, select Parallel(all at a once)
    Expand Task Options, select ‘Assign a task to each member within groups’
    Open the action properties, make sure ExpandGroup is Yes
    Also in SharePoint Designer ,you can edit the property for the Start Approval Porcess to enable ExpandGroup:
    Reference:
    https://social.msdn.microsoft.com/Forums/office/en-US/d14da1c4-bd5a-459b-8698-3a89bb01e6ad/expand-groupnot-creating-tasks-for-users-issue-in-sharepoint-2013-designer-workflow?forum=sharepointgeneral
    https://social.technet.microsoft.com/Forums/office/en-US/ac245d45-ff66-4341-815c-79213efc4394/sharepoint-2010-designer-workflows-and-sharepoint-user-groups?forum=sharepointcustomizationprevious
    Best Regards,
    Eric
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • MIRO didnt validate GL field status group

    Is it an SAP standard for MIGO not to read/validate GL account's FSG?
    Scenario:  GL account from PO has field status group Cost center required and WBS suppressed.
    During Invoice user was able to enter WBS data in the WBS column, system should have not allowed use to put WBS since FSG is WBS suppressed.
    When we tried the same scenario in FB50, FB60, FB70
    System won't allow us to enter WBS data in the WBS column, which is correct and should have happened to MIRO
    Thanks in advance to all.

    Does it matter if it was changed?
    The posted GL account has FSG of WBS suppressed, but in FB03 display data entry and GL view posting shows an entry of WBS element.
    Line item display the WBS element is not there since FSG (screen) is WBS suppressed.

  • Has anyone got a script to read a list of email addresses from a Mail message and put them into a group in Contacts?

    Has anyone got a script to read a list of email addresses from a Mail message header and put them into a group in Contacts?

    Now Tony, I know you can't hear my tone on a forum post but I was not complaining, simply stating facts . This change brought several people in my office to a grinding halt in a long established workflow that is really rather simple (and I thought was already assumed from the original post above ):
    1) Select a set of records in FileMaker Pro 12 and export only their e-mail addresses as a CSV file.
    2) Open that CSV file in Excel.
    3) Copy the column of e-mail address.
    4) paste into the appropriate recipient field in Mail.
    5) Send
    If I were to complain it would be about Apple's typically opaque approach to updates. There is no granular explanation of why changes were made or even "what" changes were made.
    Complaining is futile since Apple is Apple and is unlikely to change, but sometimes it is cathartic to "shout into the void" .
    I had thought about doing something with a formula in Excel and your suggestion was simple and helpful. Again, however, it is only a workaround for a long established helpful behavior that Apple has inexplicably broken/removed in Mavericks Mail.
    I, and the other posters here, would love to have the capability back rather than have to add previously unneeded steps to our workflows.
    Ultimately we may add scripting steps to the FileMaker side to export the address lists with commas inserted already if Apple ends up having permanently removed this feature.

  • Form Field Layout-Group Not Working

    I have LiveCycle 8.0 and when I select multiple text field to group them the group menu item in the layout menu is grayed out.  I've selected items by CTRL-click, lasso and no method works.  Please help.  Thanks, Roy

    you want to email it and I'll look and/or group the fields?
    [email protected]

  • Difference between field staus group for posting key and GL account

    Hi all,
    can anyone tell me what is the difference of usage for field status group in posting key and GL account as i notice the fileds are the same. during data entry, system will check both field status or how?
    thanks.

    Hi
    Both are to control the field status of the line item.
    But, the FSG of the Posting Key and the GL FSG status should not clash like below.
    Take 'Assignment' field as example :
    Posting key FS - Suppress & GL FS - Required    - will give you error message at the time of posting
    Posting key FS - Required & GL FS - Suppress    - will give you error message at the time of posting
    Otherthan the above, all other combination works
    VVR

  • Field Status Group influence when Purchase Requisition being created

    Hi!
    I have a requirement from a client regarding the influence of the Field Status Group on Purchasing Documents.
    A Filed Status Group has been created in which has the CO/PP order set as Required entry for the Account Assignment.
    This Group was then assigned to a GL Account.
    When a Goods Receipt (MIGO) against a Purchase Order is entered for a GL which requires an Internal Order, the standard error message "Field Order is a required field for G/L account 0010 4105000100 " (message # F5808) appears if the Account Assignment on the PO is incorrect & no Internal Order has been entered.
    This is fine & is how the system operates as standard.
    However, the requirement from my client is to make this error message appear when a Purchase Requisition is being entered on the system, before it is converted to a PO & then receipted.
    They believe that calling the message at the point of GR is too late in the process.
    Could anyone advise on any possible BAPI, etc which could help us with this requirement??
    Thanks,
    k

    I have gone to the Tcode which has been given,
    In the first field , I have given the company code,
    in the second field , I have given  call Plant (0002)
    Validation ......how do i give the validation please let me know
    With Regards,

  • Field Selection Group for Batch Management

    Hi All,
    I do not want to make the field mandatory for Raw Material during creation of material master.
    I checked the fileld selection group for MARA-XCHPF for ROH material type, MM01 , it is optional.
    But when i try to create the Material Master for ROH it is showing mandatory field.
    Amit Shah

    Hi,
    Go to the OMS9, here enter the Field sel. group 75 for your MARA-XCHPF, enter and then check the ROH Field refrece, if it shows required then select either Optinal entry or Hide or Display as per the requirement.
    Check and revert.
    Hrishi

  • Field Purchasing Group is disable in Shopping Cart

    Hi Expert,
    I have an issue in Shopping Cart. When i create Shopping cart in SRM, field for Purchasing Group is disable.
    I don't know why it's happened. 
    Because of this, when i create PO from SC in SRM (From Source of Supply), field purchasing group and purchasing organization in PO window is disable also and has no value (blank). And we can not edit the value also.
    Coud you help me please?
    Warm Regards,
    Rhesa Syahrial

    Anil
    Did you maintain Purch Group's Responsibility tab with Org ID of the user Org and responsible Prod categories.
    Then this Purch grp will be picked up when user from that org unit is created the SC.
    PS : Reward points if helpful.
    Regards
    Jagadish

  • -- SQL -- GROUP BY clause: non-aggregate fields mandate

    Hello,
    I was studying Databases, (particularly the retrieval of the data), and found something interesting.
    While using an Aggregate Function in the SELECT clause, it is mandatory to have all the non-aggregate fields in the SELECT clause to be there in the GROUP BY clause.
    For example,
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    The above SQL works fine.
    But, what if the user misses the dept_no in the GROUP BY clause or he/she misses the GROUP BY clause itself?
    Certainly, it is an error.
    Why is this error not handled by the database. I mean, the database should be smart/intelligent enough to add the GROUP BY clause by itself. So suppose, if I miss out the GROUP BY clause or miss a non-aggregate field from the SELECT clause when I am having at least one aggregate function on a field with at least one non-aggregated field in the SELECT clause, the database should check the GROUP BY clause at time of compilation and add the mandate missed out fields in the GROUP BY clause.
    Example,
    SQL1:_
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    SQL2:_
    SELECT dept_no, SUM(salary)
    FROM employee;
    Here, the SQL1 and SQL2, both should give me same outputs without an error.
    I am unable to understand why is this not handled?

    Hi,
    998478 wrote:
    ... If we mix aggregate and non-aggregate values then there must be a GROUP BY clause containing all the non-aggregate values. Why is this not handled by the database/compiler itself? It IS handled by the compiler itself. The compiler handles it by raising an error. The compiler has no way of knowing whether you want to remove something from the SELECT clause, or to add something to the GROUP BY clause, or not to use aggregate functions, or to use more aggregate functions, or some combination of the above. If the compiler re-wrote your code, and did any of these things automatically, it would be wrong more often than it was right, and you would (rightly) be complaining about its behavior.
    For example, this is clearly wrong:
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;What is the right way to fix it?
    <h3>1. Remove something from the SELECT clause</h3>
    SELECT    deptno
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;<h3>2. Add something to the GROUP BY clause</h3>
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ,         job
    ;<h3>3. Not use aggregate functions</h3>
    SELECT    deptno
    ,       job
    ,       sal
    FROM       scott.emp
    ;<h3>4. Use more aggregate functions</h3>
    SELECT    deptno
    ,       MIN (job)
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;These aren't all the options, either. For example, the correct fix might be to use analytic functions instead of aggregate functions.
    How can anybody say which of these is right? All of them are the right answer for some problem.
    By the way, saying that everying in the SELECT clause must be an aggregate or in the GROUP BY clause is a bit over-simplified.
    More completely, here are the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate function, then everything in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can SELECT "TO_CHAR (TRUNC(dt), 'Mon-DD')").
    Edited by: Frank Kulash on Apr 13, 2013 1:44 PM
    Added code examples.

  • Report on field Corporate Group (Group key) of the Vendor Master

    Hi,
    We have a vendor with for example 4 different locations. In SAP we have therefore 4 different vendor masters. We want to report not only per seperate vendor master but also we want to report on the vendors corporate level. Now we have populated the field Corporate group (Group key) on all 4 vendor masters.
    Are there any financial reports where you can use the field Corporate group (Group key) from the vendor master to consolidate on?
    If there are other solutions for reporting in this case then please let me know.
    Regards,
    Roel van Loon

    Hi
    I hope it is corporate group under account control tab in VM general data. If you maintain any data here - you can use vendor open line item report (FBl1n) to get the report on open items cleared items for these vendors collectively. You can see this option in dynamic selection in report - vendor master tab.
    Thanks
    Edited by: Praveen Raghavendra on Jan 16, 2009 2:38 PM

  • Carrier Details on Field status group for vendor master

    Hi,
    I have a requirement to make the SCAC and Carrier freight group as required fields on vendor master .
    but the standard SAP system requires/ allows three fields : SCAC , carrier freight group and Service agent procedure group as mandatory to be activated under the 'carrier details ' column in the field status group (transaction OB23 and OBD3).
    I want to know if there is a way to flag just the SCAC and carrier freight group as required fields for entry in vendor master .
    Thanks
    Naga Yarramsetty

    Hi All,
    Thanks for your reply. With user exit and validation, I cannot create mandatory mark in FS00. Actually SAP make this description always mandatory. But there is no mandatory mark in this column. I just want to create mandatory mark in this column. Need you advice.
    Thanks,
    John

  • Field Status Group for Special G/L Indicators

    Could you define different field status group for special G/L indicators? My problem is I am using two different special G/L indicators but their recon accounts are assigned with the same field status group. I used the same posting keys as well.  But when it comes to general posting, they have different screen numbers.  One SAPMF05A 303 and the other one is SAPMF05A 304.  How did this happen?

    Hi Noel,
    As you have defined Field Status Group for 2 different SPL GL Indicators then it will create 2 different screens only as it wont consider the reconciliation account.
    Regards
    andrew

  • Field"Code group" is not in the result for report CRM_SRV_REPORT

    Hi Guys,
    For the tx CRM_SRV_REPORT - Service Process Monitor, the field "Code group" is not in the standar result, but, is in the initial screen for filter selection.
    This field is not available in the layout modification.
    How can I add this field to the layout of the result list?
    Regards,
    Lyda

    Hi Lyda,
    Additional field cannot be added in the layout of the result list.
    If you will observe the code of the report CRM_TSRV_REPORT, in the field catalog, there is not Code, code group etc., hence it is not seen in the layout.
    Since it is a std report it cannot be modified, either u can create a Z report by copying this or u can raise an OSS message for this.
    Regards,
    Shalini Chauhan

Maybe you are looking for

  • SAP ABAP Client proxy Errror occured when determining the Business system.

    Dear Friends    I am trying to push data from ECC to PI and then MS-SQL Server. My SAP scenario is ABAP Proxy to JDBC   I have created on Enhancement Implementation for AS01 ( Asset Master creation). Here I am calling my ABAP proxy and uploading ANLA

  • TNS-12560: TNS:protocol adapter error (when starting database)

    Hi.. everyone. I am testing oracle9i and oracle10g on the same machine, windows xp pro. When I was trying to start oracle10g using command line mode, I got the error, TNS-12560: TNS:protocol adapter error. I entered these command. set oracle_home=10g

  • MacBook Pro frequent freezes problem

    Hi everyone, My MacBook Pro frequently freezes despite very light use. I took it to a "genius" today, but he was not very helpful. Actually, it froze again right at the apple store while they were checking it. The log showed some errors from Quicksil

  • Adobe rep Sudarshan told me I could find an answer to my question here. So here goes.

    This afternoon I purchased humansoftware's "Vintage" plug-in for Photoshop CS6 for at the Adobe website. I tried to install it on my Mac with Adobe's Extension Manager CS6. But I failed repeatedly. I kept getting the message, "An unexpected error occ

  • Removing shake in after effects

    After deciding to take the jump to CC I discovered all that looks good has its own set of problems. I'm hoping in this discussion a skilled AE user might save me time and money. I'm a proficient Vegas Pro user. The jump from a mix of Adobe programs a