What will be query for below out put?

Request Table 
Request ID
Request Name
R1
RQ1
R2
RQ2
Part Table
PartNumber
RequestID
Amount
P1
R1
200
P2
R1
300
P1
R2
500
P2
R2
400
OutPut Table
Request ID
PartNumber
Amount
R1
500
R1
P1
200
R1
P2
300
R2
900
R2
P1
500
R2
P2
400
Thanks and Regards, Vinayak Panchal

Try the below:
create Table Request (Request_ID varchar(100),Request_Name Varchar(100))
Insert into Request Values
('R1','RQ1'),
('R2','RQ2')
Create Table Part(PartNumber Varchar(10),RequestID varchar(10),Amount int)
Insert into Part Values
('P1','R1',200),
('P2','R1',300),
('P1','R2',500),
('P2','R2',400)
Select * From
SELECT Request_ID,B.PartNumber,
SUM (Amount) AS [Amt]
FROM Request A
Inner Join Part B on A.Request_ID = B.RequestID
GROUP BY ROLLUP(Request_ID,PartNumber)
)A
Where Request_ID Is not null
Order by Request_ID asc,PartNumber asc
Drop table Request,Part

Similar Messages

  • 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

  • How to place nulls has last rows.Find query for below problem

    I have a table..MyTable(value number(10))
    select * from Mytable;
    value
    12
    null
    13
    null
    11
    null
    This is the table i have and the records i have...... and i need output like this
    value
    12
    13
    11
    null
    null
    null ..............>ike this i need output for this i use this query i.e
    Query-->select value from mytable where value is not null
    union all
    select value from mytable where value is null
    ------------>and this query gives only one column result i need multiple results like below: i have table with 2 columns like below
    MyTable2(value1 number(10),value2 number(10))
    select * fromMyTable2
    value1 value2
    111 null
    null 201
    112 null
    null 200
    110 null
    this is the table i have......... and i need output like below
    value1 value2
    111 201
    112 200
    110 null
    null null
    null null
    NOTE:: If we use ORDER BY table records order must change, i don't want to change any order....please what is the query for that

    I'm not able to find any sense in your request but it can be done:
    select value1, value2
    from (select value1, rownum rn from
             (select value1 from mytable where value1 is not null
               union all
              select value1 from mytable where value1 is null)
            ) a,
           (select value2, rownum rn from
             (select value2 from mytable where value2 is not null
               union all
              select value2 from mytable where value2 is null)
            ) b
    where a.rn = b.rn;You should study some book about relational databases to understand frst of all what a record is, and then that records in a table are not ordered.
    Max

  • What value should be for below parameters

    Dear all,
    Please suggest what value should be for below parameters  in Win 2003 ,ecc6 and oracle 10g and 16 gb ram.
    Parameters     Description     Current value     
    fixcontrol     Bug fix control parameter           
    For information about the recommended settings for parameter FIXCONTROL,  version of Oracle release 10.2.0.4 a number of values must be set.
    Parameters     Description     Current value     
    max_dump_file_size     Maximum size of the optimizer trace file     UNLIMITED     
    optimizer_index_caching     Adjust the usage of nested loops     0     
    optimizer_index_cost_adj     Percentage of the calculated index costs     100     
    parallel_max_servers     Parallel Query: Maximum number of parallel execution servers     150     
    PARALLEL_MAX_SERVERS.
    Parameters     Description     Current value     
    parallel_threads_per_cpu     Number of parallel execution processes/threads per CPU     2     
    shared_pool_reserved_size     Part of Shared Pool for large statements     128676003     
    pushjoin_union_view     Enable pushing join predicate inside a union all view           
    Regards,
    Kumar

    Hello Kumar,
    The following should be the recommended parameters for your case. Always take a backup of initSID.ora and spfileSID.ora file before making the changes.
    fixcontrol Bug fix control parameter
    *._fix_control='5705630:ON','5765456:3','6221403:ON','6329318:ON','6399597:ON','6430500:ON','6440977:ON','6626018:ON','6670551:ON','6972291:ON','7325597:ON','7692248:ON','7891471:ON'
    max_dump_file_size = 20000
    optimizer_index_caching Adjust the usage of nested loops 0
    optimizer_index_caching (do not set)
    optimizer_index_cost_adj Percentage of the calculated index costs 100
    optimizer_index_cost_adj = 20
    parallel_max_servers=20
    parallel_threads_per_cpu = 1
    shared_pool_reserved_size
    CPUs   Shared_Pool_Size  
       4              500M                
       6                1G                   
      10                1G                
      32                2G                
      64                2G                
    128                3G      
    Resize db_cache depending on your needs. For your case, I would recommend at least 2GB of RAM for db_cache
    pushjoin_union_view
    pushjoin_union_view = false
    Set this as true if 6917874 fix is implemented.
    In addition Oracle processes should be calculated as follows
    Oracle Processes =
    { ABAP WP X 2  +
    J2ee Server Processes*MaxConnection  + Parallel_Max_Servers   + 40 }
    Hope I am clear.
    Thanks,
    Venkatesh Pydi.

  • How to write sql query for below example.

    Hi,
    I have requirement.
    There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
    example: table TEST.
    COLA COLB COLC COLD
    MANAGER 5 NULL null
    SR.MANAGE 6 3 NULL
    VP 5 5 4
    I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
    I need output as below.
    COLB COLC COLD
    5(MANGER) 3(sr.manger) 5(vp)
    Please provide the for above mentioned output.
    Thanks

    <<if COLA IS MANAGER THEN CONSIDER MANGER RECORD>>
    What does this sentence means? COLA does not cnatin a single record but the number of records with diffrent values.
    Regards
    Arun

  • What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10?

    Hi Guys,
    What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10?
    I have to write an AP Invoice Aging Report in Discoverer to show all unpaid invoices that have been transferred into GL... Business wants it to match one-to-one with the AP Trial Balance standard report...
    Business wants to run the report for any date in a past...
    The report has two parameters:
    As Of Date - the same as As of Date for the AP Trial Report
    Trial Balance Run Date - the date when Trial Balance was run...
    Conditions are:
    TRUNC(Invoice Date) <=TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    TRUNC(NVL(Payment Date,'01-JAN-5000')) > TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    TRUNC(Invoice Creation Date) <= TRUNC(NVL(TO_DATE(:Trial Balance Run Date),SYSDATE))
    Distr Accounting Date <= TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    NVL(Distr Creation Date,Invoice Creation Date) <= TRUNC(NVL(TO_DATE(:Trial Balance Run Date),SYSDATE))
    Show_Flag = 'YES', where:
    Show_Flag = CASE WHEN ( NVL(Cancelled Date,'01-JAN-1901') > NVL(:As Of Date,SYSDATE) AND NVL(Inv Amount Aud,0) = 0 ) THEN 'YES' ELSE ( CASE WHEN NVL(Inv Amount Aud,0) = 0 THEN 'NO' ELSE 'YES' END ) END
    There is a difference between the logic of my report, and the logic of AP Trial Balance...
    Could you please advise what I'm missing?
    Thanks,
    Iana

    What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10? You can get the code by opening the report in Reports Builder and get the query.
    Or, enable trace/debug as per (FAQ: Common Tracing Techniques within the Oracle Applications 11i/R12 [ID 296559.1]).
    Thanks,
    Hussein

  • Hello, i have buy iphone 6 recently now it is fall down on the ground and any chance to repair buy apple on free of cost if not then what will be price for this

    Hello, i have buy iphone 6 recently now it is fall down on the ground and any chance to repair buy apple on free of cost if not then what will be price for this

    santosh7783 wrote:
    and its screen is break down please help me
    iPhone 6 screen replacement is $109 U.S.
    => https://www.apple.com/support/iphone/repair/screen-damage/

  • How to write sql query for below mentioned eaxmple.

    Hi,
    I have requirement.
    There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
    example: table TEST.
    COLA COLB COLC COLD COLE COLF MANAGER 5 NULL NULL 3 NULL
    SR.MANAGER 6 3 NULL NULL NULL
    VP 5 5 4 5 5
    I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
    I need output as below.
    COLB COLC COLD COLE COLF
    5(manager) 3(sr.manger) 4(vp) 3(manger) 3(vp)
    Please provide the for above mentioned output.
    Thanks

    Duplicate thread. please view the answer posted in your first thread.
    how to write sql query.
    And, please don't post any duplicate thread.
    Regards.
    Satyaki De.

  • Provide sql query for below one

    hi everyone,
    in my source table [finanace_dept] contains two columns [finance_id,r_mature_kd] with 2 million records and sample data given below.
    finance_id r_mature_kd
    1 H
    1 T
    1 T
    2 T
    3 H
    4 S
    4 T
    4 T
    5 X
    6 H
    6 L
    6 L
    6 M
    please provide sql query for below expected output.
    expected output :
    finance_id r_mature_kd
    1 H
    1 T
    4 S
    4 T
    6 H
    6 L
    6 M
    for column finance_id: '1', contains three records, but two distinct r_mature_kd hence it should retrive only two records with H,T
    for column finance_id: '2','3', contains only one record hence this records should not retrive.
    for column finance_id: '6', contains four records, but three distinct r_mature_kd hence it should retrive only two records with H,L,M
    please help on this.

    WITH T(finance_id,r_mature_kd) AS (
    SELECT 1, 'H' FROM DUAL UNION ALL
    SELECT 1, 'T' FROM DUAL UNION ALL
    SELECT 1, 'T' FROM DUAL UNION ALL
    SELECT 2, 'T' FROM DUAL UNION ALL
    SELECT 3, 'H' FROM DUAL UNION ALL
    SELECT 4, 'S' FROM DUAL UNION ALL
    SELECT 4, 'T' FROM DUAL UNION ALL
    SELECT 4, 'T' FROM DUAL UNION ALL
    SELECT 5, 'X' FROM DUAL UNION ALL
    SELECT 6, 'H' FROM DUAL UNION ALL
    SELECT 6, 'L' FROM DUAL UNION ALL
    SELECT 6, 'L' FROM DUAL UNION ALL
    SELECT 6, 'M' FROM DUAL
    SELECT  DISTINCT finance_id,r_mature_kd,C FROM(
    SELECT finance_id,r_mature_kd,COUNT(1) OVER (PARTITION BY finance_id) C
    FROM T
    WHERE C > 1
    ORDER BY 1
    FINANCE_ID
    R_MATURE_KD
    C
    1
    H
    3
    1
    T
    3
    4
    S
    3
    4
    T
    3
    6
    H
    4
    6
    L
    4
    6
    M
    4
    Ramin Hashimzade

  • How much will it cost for an out of warranty repair for a water damaged iPhone 4S in the UK?

    How much will it cost for an out of warranty repair for a water damaged iPhone 4S in the UK?
    I got water in my iPhone 4S (not drenched as it was within a LifeStyle waterproof case).
    I dried it out in a bowl of rice, but the phone no longer charges, will not allow wifi, cannot locate network.

    You have to get a refurbished iPhone. As your phone is out of warranty, you will have to pay £139 at an Apple Store in order to get it > http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=ipho ne

  • What will be input for custom module developed for JDBC adapter

    Hi,
    I have a scenario SQLDB -> Xi -> R3 .
    Here I have added a custom module before callsapadapter module.
    As I know the sequence of module calling will be as follows :
    1. Standard jdbc adapter
    2. custom module
    3. callsapadapter
    Standard jdbc adapter has a select query . After that what will be the input format for my custom module .Will it be the xml structure of my source Data type or will it be a resultset or will it be a inputstream(stream of xml fomat????).
    And then in which format i need to generate the output format for CallSapAdapter.
    Regards

    Hello Moni,
    SAP has a wonderful feature in ABAP. There are some Runtime Errors that you can <i>catch</i>. This is somewhat similar to the Exception Handling procedure in Java / C++. So here's how you go about it....
    Sometimes there might some calculations that we do, multiplication , for example, where the result of the arithmetic operation is known only at run-time. And the recepient for this result may not always be of the right type to take the result. Consider the following code:
    parameters a type i obligatory.
    data : b type i,
           c type i.
    b = 99999999.
    ** Assume that the user has entered 99999999 for the value of the parameter a.
    c = a * b.    " 99999999 * 99999999 "
    write c.
    This program will certainly give a short dump saying that there was an arithmetic overflow. But we can actually avoid this Shor Dump and handle the situation quite elegantly. consider the following.
    parameters a type i obligatory.
    data : b type i,
           c type i.
    b = 99999999.
    CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 1.
    ** Assume that the user has entered 99999999 for the value of the parameter a.
       c = a * b.    " 99999999 * 99999999 "
    ENDCATCH.
    if sy-subrc ne 0.
      write: 'There was an arithmetic overflow in the calculation.'
    else.
      write c.
    endif.
    This way you can actually avoid the short dump and make the system set a value for sy-subrc. Based on the avlue of the sy-subrc, you can go ahead with further processing / error-handling, as the case may be.
    Here, ARITHMETIC_EXCEPTIONS is called an <i>exception group</i>. For more information on what other run-time errors can be <i>caught</i>, and What the various exception groups contain, please refer to the online documentation for the CATCH statement.
    Regards,
    Anand Mandalika.

  • What will they do for us?

    If your screen is scratched and apple is being sued for that reason..does anyone know what they are doing for their carelessness for the consumer product?

    No offense but how is Apple responsible for people who scratch up their iPod? I don't own one single thing that can NOT be scratched. NOTHING. Every single thing can be scratched, gouged, or maimed. Just the other day I took a healthy chunk of paint off of my car with the key to my car, quite by accident. Is Honda careless? Hardly. If you don't want to scratch up your iPod take precautions. That's what photographers do when they buy an expensive lens. It's what Palm owners do when they buy an expensive unit. I took my iPod right out of the box and put a screen protector on it (I had some leftover from previous Palms I've owned) and my iPod can't be scratch easily (but it could still be scratched). Apple wouldn't have anything to do with whether or not it got scratched after it's out of the box.
    If you opened up the box and it was scratched in the box (mine wasn't) that would be one thing but if YOU have used it and it got scratched - YOU scratched it.
    A little personal accountability would go a long way here.
    Over and out.

  • How to write query for below requirement

    Hi sir,
    i have a table x have one column y which containing value like below
    Y
    a
    b
    c
    d
    I want out put like below  kindly help me:
    Y
    a
    d
    c
    b

    Hi ,
    Please check:
    select y from (
    select case when y='a' then 1 else 2 end no, y from table_x
    ) order by no asc, y desc
    with table_x as(
    select 'a' y
      from dual
    union  
    select 'b' y
      from dual
    union 
      select 'c' y
      from dual
    union  
      select 'd' y
      from dual
    select y from (
    select case when y='a' then 1 else 2 end no, y from table_x
    ) order by no asc, y desc
    Thank you

  • How to write select query for below requirement

    Hi sir,
    i have a table x have one column y which containing value like below
    Y
    a
    b
    c
    d
    I want out put like below  kindly help me:
    Y
    a
    d
    c
    b

    Hi ,
    Please check:
    select y from (
    select case when y='a' then 1 else 2 end no, y from table_x
    ) order by no asc, y desc
    with table_x as(
    select 'a' y
      from dual
    union  
    select 'b' y
      from dual
    union 
      select 'c' y
      from dual
    union  
      select 'd' y
      from dual
    select y from (
    select case when y='a' then 1 else 2 end no, y from table_x
    ) order by no asc, y desc
    Thank you

  • 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

Maybe you are looking for