Query for required out put as mention below in SQL

HAI..
all
I HAVE A TABLES LIKE
SQL> SELECT *FROM A;
PCK PN
1 BIKES
2 COMPONENTS
SQL> SELECT *FROM B;
PSC PCK SBNAME
1 1 RASEBAIKE
2 1 SPEEDBIKE
3 2 MOTHERBORD
4 2 HARDIDSK
5 1 SPORTSBIKE
6 2 RAM
SQL> SELECT PN,SBNAME,COUNT(*) FROM A,B WHERE A.PCK=B.PCK GROUP BY ROLLUP(PN,SBNAME);
PN SBNAME COUNT(*)
BIKES RASEBAIKE 1
BIKES SPEEDBIKE 1
BIKES SPORTSBIKE 1
BIKES 3
COMPONENTS RAM 1
COMPONENTS HARDIDSK 1
COMPONENTS MOTHERBORD 1
COMPONENTS 3
6
I want output like this how to avoid duplicates in PN column in SQL
OUTPUT
1 BIKES
1 RASEBAIKE
2 SPEEDBIKE
5 SPORTSBIKE
2 COMPONENTS
3 MOTHERBORD
4 HARDIDSK
6 RAM

Kindly place \ before and after your data and code \try this
with a as
  select 1 pck, 'BIKES' pn from dual union
  select 2, 'COMPONENTS' from dual
, b as
  select 1 psc, 1 pck, 'RASEBAIKE' sbname from dual union
  select 2, 1, 'SPEEDBIKE' from dual union
  select 3, 2, 'MOTHERBORD' from dual union
  select 4, 2, 'HARDIDSK' from dual union
  select 5, 1, 'SPORTSBIKE' from dual union
  select 6, 2, 'RAM' from dual
select case
            when nvl(a.pn, 'ALL') = lead(a.pn) over (partition by a.pn order by a.pn) then
              null
            else
              nvl(a.pn, 'ALL')
       end pn
      ,b.sbname
      ,count(*)
from a, b
where a.pck = b.pck
group by rollup(a.pn, b.sbname)
PN         SBNAME       COUNT(*)
           RASEBAIKE           1
           SPEEDBIKE           1
           SPORTSBIKE          1
BIKES                          3
           HARDIDSK            1
           MOTHERBORD          1
           RAM                 1
COMPONENTS                     3
ALL                            6if you want the output as follows:
PN         SBNAME       COUNT(*)
BIKES      RASEBAIKE           1
           SPEEDBIKE           1
           SPORTSBIKE          1
                               3
COMPONENTS HARDIDSK            1
           MOTHERBORD          1
           RAM                 1
                               3
ALL                            6then simply modify LEAD to LAG

Similar Messages

  • How to debugg a script when the Required out put is like Fax  or email

    Hi this is Durga Prasad i have small doubt in scripts can any one clarify that one plz  normally we will do that one with activating debugger but when a special requirement is like fax or e mail    how we will do that one
    "how to debugg a script when the Required out put is like Fax  or email"
    Thanks in advance
    Durga Prasad.

    Hi
    DEBUG Smartform:
    1) One way to debug smartform is to debug the Function Module of that smartforms.
    If you want to debug particular smartform node that the solution would be,
    insert a "Program Line" just above the node you want to debug and this program line write a normal abap breakpoint.
    So whenever you call the smartforms, it will stop at this breakpoint and you can debug onwards.
    2) SFTRACE can be used for debugging SMARTFORMS.
    Read More here.
    http://help.sap.com/saphelp_erp2004/helpdata/en/49/c3d8a4a05b11d5b6ef006094192fe3/frameset.htm
    script
    1). Use Tools - Word Processing - Layout Set (SE71). Enter name of layout set and then Utilities - Activate Debugger.
    It is of no consequence which layoutset you enter when selecting the SAPscript debugger. (Menu path: Tools-Wordprocessing - Forms, Utilities - Activate Debugger) The next layoutset called will invoke the debugger.
    2). Another way to set the SAPScript debugger is to run program RSTXDBUG.
    When you debug Print program it is same as you debug any other ABAP program. While when you debug SAPScript, you actually debug the code ( scripting) you have written SAPScript Form.
    As per ur question there is nothing new with script debugging,
    it is same as normal report debugging...
    SMARTFORMS DEBUGGING
    For smartforms debugging you can do this.
    1. Execute the smartform (execute button in SMARTFORMS transaction)
    2. Take the generated function module and display it in SE80.
    3.Find the smartforms Elements (text elements, windows, code lines, loops) in this and set Soft break points.
    Correct name is SMARTFORM_TRACE. You have lots of options for adequate analysis
    Tcode - SFTRACE
    Re: How to Debug a Smartform
    Debug of smartform and sapscript.
    Debugging SmartForms
    Debugging of a subroutine pool.
    SCRIPT
    There are 2 separate kinds of debugging available when you try to debug scripts.
    1. Debugging the print program : This is the normal debugging we do for our report programs.
    2. Debugging the script itself : You Can debug a SAP Script by activating debugger in two ways:
    a .In SE71->Menu->Utilities->Activate Debugger, then debugger will be get activated and when your print program is executing Script Debugger will be in active and you can proceed with your debugging.
    b. Goto se38-> RSTXDBUG ->Execute this same as going thru in se71-> Menu, now debugger will be activated.
    refer to the link below
    http://www.howforge.com/how-to-debugging-sapscript-form
    Look at the BLOG here, it is well explained
    /people/sudheer.junnuthula2/blog/2007/01/09/script-debugging
    Regards
    Anji

  • Please give the query to find out primary key in table in Sql plus

    Dear friends,
    Please give me the query to find out the primary key in Sql plus.

    hi
    SQL> DESC user_constraints
    Name                                                                                                  
    OWNER                                                                                                 
    CONSTRAINT_NAME                                                                                       
    CONSTRAINT_TYPE                                                                                       
    TABLE_NAME                                                                                            
    SEARCH_CONDITION                                                                                      
    R_OWNER                                                                                               
    R_CONSTRAINT_NAME                                                                                     
    DELETE_RULE                                                                                           
    STATUS                                                                                                
    DEFERRABLE                                                                                            
    DEFERRED                                                                                              
    VALIDATED                                                                                             
    GENERATED                                                                                             
    BAD                                                                                                   
    RELY                                                                                                  
    LAST_CHANGE                                                                                           
    INDEX_OWNER                                                                                           
    INDEX_NAME                                                                                            
    INVALID                                                                                               
    VIEW_RELATED                                                                                          
    SQL> SELECT constraint_name,table_name,r_constraint_name,status
      2  FROM user_constraints WHERE constraint_type='P';
    CONSTRAINT_NAME                TABLE_NAME                     R_CONSTRAINT_NAME              STATUS
    SYS_C003141                    CUSTOMERS                                                     ENABLED
    PK_DEPT                        DEPT                                                          ENABLED
    SYS_C003139                    SALESREPS                                                     ENABLEDKhurram

  • Need to adjust SQL query for left outer join in Crystal Reports 2008.

    I need to change this SQL 2005 query.....
    SELECT     omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
                          omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
                          omnicell_anl.labeledLastMetrics.latest_monitor_value
    FROM         omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
                          omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id
    WHERE
        omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
    To this query in Crystal Reports Report Writer:
    SELECT     omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
                          omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
                          omnicell_anl.labeledLastMetrics.latest_monitor_value
    FROM         omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
                          omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id AND
                          omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
    I can't seem to get the left outer join function of Crystal Reports to emulate the same SQL query in SQL 2005.  Any ideas on how I can create this same query in Crystal 2008?
    Thanks,
    Dominic
    Edited by: Dominic Carissimi on Oct 28, 2008 7:55 PM
    Edited by: Dominic Carissimi on Oct 28, 2008 7:56 PM

    If you want the list of values for command level parameter then you need to add another command like
    select PropertyField from table
    and delete the links between this command and the existing command.
    Now go to field explorer and edit the command level parameter and make it as dynamic and add the property field from newly added command.
    Hope this helps!
    Raghavendra

  • Query for required format

    my table data
    no name address
    ================
    10 aaa pune
    10 aaa mumbai
    20 bbb chennai
    20 bbb hyd
    i want the output as below
    no name address1 address2
    =========================
    10 aaa pune mumbai
    20 bbb chennai hyd
    please anybody help on this

    What is your DB version?
    What if there are more than two addresses for a person? Do you expect a column address_3?
    FAQ: {message:id=9360002}
    You are looking for some kind of pivoting, and the answer is here, below
    Read FAQ: {message:id=9360005}
    The FAQ link above has almost all the way to do static and dynamic pivoting.. Go throuth the same, try yourself - if you are facing an issue, put the specific question in this forum along with your code..
    Edited by: jeneesh on Nov 15, 2012 2:14 PM

  • Query - selection screen out put only

    Hi,
    I have developed a Query in Sq01, I have to make the selections screen field as grey out with default value,
    i have done with default value but user can edit it using his own
    but I want it to be displayed only.
    please help.
    regards,
    Prabhu
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Apr 30, 2008 5:12 PM

    hi,
    did you try to set variant protection?
    greetings,darek

  • Query not showing out put

    i am writing SQL lines they are part of my stored procedure there is not any error in this but this not
    showing me any result but giving me message anonymous block completed
    set serveroutput  on
    declare
    var varchar(50);
    re varchar(50);
    begin
    var:='zoheb123456789';
    re :=length(var);
    if re!='' then
    dbms_output.put_line(var);
    dbms_output.put_line(re);
    else
    dbms_output.put_line('no');
    end if;
    end;please help me
    Edited by: BluShadow on 14-Feb-2011 08:53
    to show code tags and convert &lt;&gt; to != for the forums

    sql> declare
      2    var varchar(50);
      3    re  varchar(50);
      4  begin
      5    var:='zoheb123456789';
      6    re :=length(var);
      7    if re != ''
      8    then
      9      dbms_output.put_line(var);
    10      dbms_output.put_line(re);
    11    else
    12      dbms_output.put_line('no');
    13    end if;
    14* end;
    15  /
    no
    PL/SQL procedure successfully completed.As you can see, it works in sql*plus.
    The result, "no" may not be what you expect. The reason for this is the handling of the empty string, in
    if re != ''Oracle translates '' to null:
    if re != nullThis will always evaluatie to false (null checking should be of course be done with IS [NOT] NULL).
    BTW: why is re varchar2 anyway? It is assigned a numeric value, so changing it into numeric would be better. And you would avoid the faulty null checking.

  • Query for finding out which components are in use

    Hi,
    I had a query once to check, if specific components are in use. Theres some internal view but i just can't remember. Can someone help me with this?
    EDIT: Damn it wrong board...
    Edited by: torgum on Nov 2, 2009 10:51 AM

    Key binding may vary as you switch between programs. I have some set to be "universal" but some applications manage to override those settings even though the key shortcuts in the application's menu show my programmed shortcuts.
    In your case I'd try disabling applications you suspect may potentially be effecting problems and see if you can track down which are affecting your other applications.

  • I want sql query for this output

    hi guys
    could u tell how can i write sql query for this out put
    i have one table like this
    ID ACCOUTID TAX
    1 1 A
    2 1 B
    3 2 C
    4 2 D
    5 3 E
    7 NULL F
    8 NULL G
    MY OUT PUT MUST BE LIKE THIS
    ID AID TAX
    2 1 A
    4 2 D
    7 NULL F
    8 NULL G
    HERE IN THIS OUTPUT I SHOULD HAVE
    MAXIMAM ID VALUE FOR A REPEATED AID VALUES
    AND
    THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
    I KNOW ONE SOLUTION LIKE THIS
    SELECT MAX(ID),AID,TAX
    FROM TABLE T
    GROUP BY AID,TAX
    UNION ALL
    SELECT ID, AIC,TAX
    FROM TABLE T
    WHERE AID IS NULL;
    BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
    COULD U PLZ TELL A SOL.

    Will this help:
    SQL> with t as
      2    (
      3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
      4      select 2, 1, 'B' from dual union all
      5      select 3, 2, 'C' from dual union all
      6      select 4, 2, 'D' from dual union all
      7      select 5, 3, 'E' from dual union all
      8      select 7, NULL, 'F' from dual union all
      9      select 8, NULL, 'G' from dual
    10    )
    11  --
    12  select id, ACCOUTID AID, Tax
    13  from
    14  (
    15    select t.*
    16          ,count(1)       over (partition by t.ACCOUTID) cn
    17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
    18    from t
    19  )
    20  where cn > 1
    21  and (rn = 1 or ACCOUTID is null)
    22  /
            ID        AID T
             2          1 B
             4          2 D
             8            G
             7            F
    -- If I leave out the OR condition then you'll get this:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (
      3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
      4      select 2, 1, 'B' from dual union all
      5      select 3, 2, 'C' from dual union all
      6      select 4, 2, 'D' from dual union all
      7      select 5, 3, 'E' from dual union all
      8      select 7, NULL, 'F' from dual union all
      9      select 8, NULL, 'G' from dual
    10    )
    11  --
    12  select id, ACCOUTID AID, Tax
    13  from
    14  (
    15    select t.*
    16          ,count(1)       over (partition by t.ACCOUTID) cn
    17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
    18    from t
    19  )
    20  where cn > 1
    21* and rn = 1
    SQL> /
            ID        AID T
             2          1 B
             4          2 D
             8            G
    --which follows the description you've given, but not the output

  • MRP list out put tables for header and item -reg

    Hi ,
    What is the table to be used for MRP out put
    header is MDKP
    for item what is the table ?
    regards,
    madhu kiran

    Dear,
    Tthe MRP item data is stored in a data cluster. The database
    table is MDTC, and the data cluster area is ar. Use the following command to
    import the data from the data cluster:
    Import <structure> from database mdtc(ar) ID <key>.
    The ID key value comes from the field dtnum (Number of the material
    requirements planning table) in table MDKP
    MDKP MDTB MDKP
    Please refer this also,
    [Table for MRP item|table for MRP item]
    Regards,
    R.Brahmankar

  • How to give F4 Help for out put screen

    Hi ,
    I have out put grid display which is editable , in that i want to give F4 help for one of the eidtable field. if any body know about this please me .
    My problem is i need to add F4 for my out put screen.
    Thanks ,
    saleem.

    Check the following code it may hel u.
    REPORT ABC.
    DATA : BEGIN OF ITAB OCCURS 0,
    UNAME LIKE USR01-BNAME,
    END OF ITAB.
    data : RETURN_TAB LIKE DDSHRETVAL occurs 0 .
    data : RETURN_wa LIKE DDSHRETVAL .
    PARAMETERS : A(12) TYPE C.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR A.
    ITAB-UNAME = 'U01'. APPEND ITAB.
    ITAB-UNAME = 'U02'. APPEND ITAB.
    ITAB-UNAME = 'U03'. APPEND ITAB.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    DDIC_STRUCTURE = ' '
    retfield = 'ITAB-UNAME'
    PVALKEY = ' '
    DYNPPROG = SY-REPID
    DYNPNR = SY-DYNNR
    DYNPROFIELD = 'A'
    STEPL = 0
    WINDOW_TITLE =
    VALUE = ' '
    VALUE_ORG = 'S'
    MULTIPLE_CHOICE = ' '
    DISPLAY = ' '
    CALLBACK_PROGRAM = ' '
    CALLBACK_FORM = ' '
    MARK_TAB =
    IMPORTING
    USER_RESET =
    tables
    value_tab = ITAB
    FIELD_TAB = FTAB
    RETURN_TAB = return_tab
    DYNPFLD_MAPPING =
    EXCEPTIONS
    PARAMETER_ERROR = 1
    NO_VALUES_FOUND = 2
    OTHERS = 3
    Regards

  • PO E-Mail Out Put Error ( E-mail address incorrect or non-existent )

    Hi Gurus,
    I'M getting the error " E-mail address incorrect or non-existent" when i process the out put type for email of PO.
    I maintained all the settings which are mentioned below ,
    Goto NACE .
    u2022 Select EF and click on OUTPUT TYPES.
    u2022 Then select Output Type NEU and click on processing routines .
    u2022 In that you have to add a new entry - medium 5 .
    u2022 Then you need to assign a program, form routine and form.
    u2022 You can use the standard program i.e. SAPFM06P, FORM routine is always ENTRY_NEU and standard MEDRUCK.
    u2022 Then in PARTNER FUNCTION you need to add a new entry : medium - 5 and function - VN .
    u2022 For subject of the mail goto Mail Title and Texts. In title give PO No. &EKKO-EBELN& .
    u2022 Under General data -> Replacement of text symbols give programm as SAPMM06E and Form Routine as TEXT_SYMBOL_REPLACE .
    u2022 You need to maintain your email id in tcode SU01 and also the vendor's email id.
    u2022 Now while creating a new purchase order , change the medium to External Send .
    u2022 Then goto Communication Method and select CS01 . ALSO make sure that the Cover Page Text has value PO No. &EKKO-EBELN& .
    u2022 Goto tcode ME9F .
    u2022 Execute. 
    Still I'm getting  the same error " E-mail address incorrect or non-existent". could any body help me in this issue?
    Regards,
    Sri.........

    Hi Deepak
    I have gone through the notes which u have mentioned, but it is not helping to my query,
    I had maintained SMTP port in the tcode SCOT.Then I'm getting the message "MAIl request 000000000002 created" when I run tcode ME9F for email out put.But I'm not getting the out put in the email address which I specified in the vendor master record. I can see one error in the transaction code SCOT. should i run transaction SCOT manually every time ?
    Regards,
    Sri...........

  • Automatic out put determination (PO massage setting)

    Dear Friend,
    Can any body so kind answer my following query ?
    1. What is the use of ' massage determination schemas' for PO out put control ?
        Path : spro -
    > material management -
    > Purchasing -
    > massages -
    > output control -
    > massage determination schemas -
    > define massage schema for PO -
    > Maintain Message Determination Schema: Purchase Order -
    > control data
    2. what is the use of requirement that present in the control data of the above mantioned path?
    3 What is the logic of 101 requirement ?
    Your reply will be highly apprecieted.
    Thanks in advance.
    Regards,
    sp sahu

    Dear Sahu,
    The IMG path is to control what condition type is allowed in outputing PO form.
    101 is enable users to Re-print/Re-create another new condition after the PO form is already print out /send.
    Regards,
    w1n

  • Print out put of Invoice Verification

    How to get print output of Invoice verification? How to get print output of  subsequent credit/debit of Invoice?

    Hi
    You need to create a new Message type copying any relevant message type.(tCode M806). Maintain the processing routines  with medium as print out put.
    Create  the form required for Print out put & assign it to the routine.
    Maintain the message schemas , Assign the new Message type to the existing schema.
    Now create the conditoin record using transaction MRM1 with th required key combination. Invoicing party & Company code.
    Now when ever you create the invcoie with combination the Message will be created.
    Execute transaction MR90 for the print out put. If you want the print after saving the invoice , maintain the despatch time as Send immediately when saving the application.
    Reward points if useful
    Thanks & Regards
    Kishore

  • Out put message

    Hi,
    I have query related to out put determination.In purchase order message determination (determination analysis -alphabet i in blue) sequence is shown as  ACE1 then AUFB then MAHN then NEU then z123 while as, as per message determination schema it is NEU then MAHN then AUFB then ACE1 then Z123.
    My queries are 1) why their is difference in sequence in message determination schema and in purchase order.My thinking is system will search  condition as per message determination schema in SPRO.
    2) From where condition ACE1 is picked up as it is not appearing in define message type for purchase order.
    Thanks & Regards
    Atharva

    Hi,
    Regarding message type ACE1 or Z123 or any other message output types in Purachse order, you can check all details  in table: NAST with t.code: SE11
    As you asked sequense of message type is diferent in message determination and in message determination schema.
    In message determination ( in NACE t.code with EF application), is started with starting from alphabate  A->Z like ie...ACE1,AUFB,ET01,MAHN,NEU,RICH & WEZL
    In message determination schema, its all in order from Print(NEU), Order Acknowledgements(AUFB) & then sending Reminders vendors (MAHN)
    Regards,
    Biju K

Maybe you are looking for

  • HP Expert Day - Sept 21, 2011: Got questions? We have experts!

    Thank you for coming to Expert Day – the event has now concluded. **To find out about future HP Expert Day events, check out this page** On behalf of the Experts, I would like to thank you for coming to the Forum to connect with us.  We hope you will

  • White line in screen display

    I got my 80GB ipod classic for Christmas. It has worked fine, but now it has a white line through the screen. It is annoying and makes watching videos a problem. Can anyone help? I don't want to send the ipod to Apple.

  • How to maintain spacing between 2 elements in webdynpro

    Hi Experts, I got 3 pushbutton. I am using matrix layout but spacing(distance) between 3 of these elements is not uniform. Please help me to make spacing between them to be uniform. Thanks & Regards, Niki

  • Itunes cannot run because some of its required info is missing. Re-install.

    I have recently upgraded my itunes and when i went to load it, it said "itunes cannot run because some of its required information is missing. Please re-install itunes*." I have done this several times while rebooting my cpu after each install/re-ins

  • Saving PDF with different option

    Does anyone have a VBscript that opens a PDF and saving it with the option of  "Reduce file size"