Need SQL query - can anyone help

have a table which contains
Name StartDate EndDate Billable NonBillbale
AAA 01-Jan-2007 31-Mar-2007 2 3
AAA 01-Apr-2007 31-Jun-2007 4 6
BBB 01-Jan-2007 31-Mar-2007 2 3
I need to create a table from this table where the entry would be
Name Jan2007Billable Jan2007NonBillable
feb2007Billable Feb2007NonBillable Mar2007Billable Mar2007NonBillable
April2007Billable April2007NonBillable May2007Billable May2007NonBillable Jun2007Billable Jun2007NonBillable
AAA 2 3 2 3 2 3 4 6 4 6 4 6
BBB 2 3 2 3 2 3
I am very new to database programming... It will be highly appreciated if anyone help me to genrate the query

This is called a PIVOT and you can see plenty of examples if you search this forum.
An example would be...
SQL> WITH t AS (select 'AAA' AS cust_name, to_date('01-jan-2007','dd-mon-yyyy') as StartDate, to_date('31-mar-2007','dd-mon-yyyy') EndDate, 2 as Billable, 3 as NonBillable from dual union all
  2             select 'AAA', to_date('01-apr-2007','dd-mon-yyyy'), to_date('30-jun-2007','dd-mon-yyyy'), 4, 6 from dual union all
  3             select 'BBB', to_date('01-jan-2007','dd-mon-yyyy'), to_date('31-mar-2007','dd-mon-yyyy'), 2, 3 from dual)
  4  -- END OF TEST DATA - "CUT HERE" --
  5  select cust_name
  6        ,sum(case when to_date('jan-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as jan2007_b
  7        ,sum(case when to_date('jan-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as jan2007_nb
  8        ,sum(case when to_date('feb-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as feb2007_b
  9        ,sum(case when to_date('feb-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as feb2007_nb
10        ,sum(case when to_date('mar-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as mar2007_b
11        ,sum(case when to_date('mar-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as mar2007_nb
12        ,sum(case when to_date('apr-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as apr2007_b
13        ,sum(case when to_date('apr-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as apr2007_nb
14        ,sum(case when to_date('may-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as may2007_b
15        ,sum(case when to_date('may-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as may2007_nb
16        ,sum(case when to_date('jun-2007','mon-yyyy') between startdate and enddate then billable else 0 end) as jun2007_b
17        ,sum(case when to_date('jun-2007','mon-yyyy') between startdate and enddate then nonbillable else 0 end) as jun2007_nb
18  from t
19  group by cust_name
20  order by 1
21  /
CUS  JAN2007_B JAN2007_NB  FEB2007_B FEB2007_NB  MAR2007_B MAR2007_NB  APR2007_B APR2007_NB  MAY2007_B MAY2007_NB  JUN2007_B JUN2007_NB
AAA          2          3          2          3          2          3          4          6          4          6          4          6
BBB          2          3          2          3          2          3          0          0          0          0          0          0
SQL>

Similar Messages

  • HT3633 I have an error message that reads: java.lang.noclassdefFounder - need to fix can anyone help?

    I have an error message that reads: java.lang.noclassdefFounder - need to fix can anyone help?

    That's a bug in whatever Java program you're running.
    That's not an error specific to OS X.
    (There's usually a whole lot more text dumped by Java, too.)
    Check with whoever wrote or is supporting the package you're working with.

  • Just plugged in my wireless printer and need assistance please - can anyone help me to start printin

    just plugged in my hp deskjet 3070A e-ALL-IN-ONE SERIES and want to do a test print - I'm not sure what I am doing and don't want to make any stupid mistakes - the software was loaded on to my new hp laptop when I bought it from PC world/currys - can anyone "talk me through" the basics that I need please?
    sorry to be such a wuss but am okay once I know what to do - if I get in a jam when first trying, I get a bit worried about what to do so would much rather get it right first time and then I can go on from there
    thanks in anticipation ...

    Since you installed it, just follow what the manual and instructions say and print away....
    Say thanks by clicking the Kudos Thumbs Up to the right in the post.
    If my post resolved your problem, please mark it as an Accepted Solution ...
    I worked for HP but now I'm retired!

  • I have a vintage ICF-111 that needs repair. Can anyone help?

    Hi,
    My ICF-111 from the 1970s needs a servicing and I have no idea where to turn.  The main problems: crackling when volume dial is adjusted and station reception no longer as good (with antenna fully out and fresh batteries).
    I would be grateful for any help!
    Many thanks.
    Eric

    Hi Eric! Unfortunately, we don't service this unit anymore. This model is beyond the supported repair period. At this time, you might want to consider putting the money you would have paid for repair toward a new product. There are many new functions and features since you purchased your portable radio. This would be a good opportunity to update your unit. You can check for our latest products on Sony Online Store here. Thank you! 
    If my post answers your question, please mark it as "Accept as Solution"
    http://bit.ly/Win-4K

  • Whats wrong with this query.can anyone help me......

    select CASE WHEN TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'DDMMYYYY HH24:MM:SS'),13,2))>0 AND TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)) <14
    THEN TO_DATE(CONCAT(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)||'00',SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MI:SS'),16)||'00'),'DD-MM-YYYY HH24:MI:SS') end
    from table;
    i have written this query.whats wrong with this query..........
    the error is "literal does not match format string"
    Reegards soumen

    Why does your date_format loose, ununify and not fix ?
    And what is your exact requirement?
    >>
    CASE WHEN
    TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'DDMMYYYY HH24:MM:SS'),13,2))>0
    AND TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)) <14
    <<
    This is
    CASE WHEN TO_CHAR(START_TIME_TIMESTAMP,'MM') between '01' and '13'
    >>
    THEN TO_DATE(CONCAT(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)
    ||'00',
    SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MI:SS'),16)||'00'),
    'DD-MM-YYYY HH24:MI:SS')
    <<
    This is
    TO_DATE(
    TO_CHAR(START_TIME_TIMESTAMP,'MM"00"SS"00"),
    'DD-MM-YYYY HH24:MI:SS')
    Obviously, format is not matching !
    SQL> select to_char(sysdate,'MM"00"SS"00') from dual;
    TO_CHAR(
    06004900
    SQL> select to_date('06004900','DD-MM-YYYY HH24:MI:SS') from dual;
    select to_date('06004900','DD-MM-YYYY HH24:MI:SS') from dual
    ERROR at line 1:
    ORA-01861: literal does not match format string

  • Can anyone help me with Query ?

    Hi Experts,
    Can anyone help me with Query? the query need to retrieve below info based on set of books ID.
    Needed columns:
    1 SOB     
    2 Legal Entities      
    3 Fixed Asset Org Name     
    4 Applications/Responsibilities     
    5 Operating Units     
    6 Inventory Org     
    7 COA     
    8 Assigned Responsibilities
    Thanks

    Duplicate post -- Can you help on below Query ?
    Please post only once!

  • Need SQL Query Help

    I need help combining two queries into one. This is what I
    have now:
    <CFQUERY NAME="getInfo" datasource="myDS"
    BLOCKFACTOR="100">
    SELECT
    status.status_doc_id,
    status.date_accepted,
    status.date_received,
    document_main.document_main_doc_type,
    document_main.document_main_doc_id,
    document_main_account_id,
    document_main_company_account_id,
    document_main_period_of_report,
    users_account.client_name,
    users_account.account_type
    FROM
    status,
    document_main, users_account
    WHERE
    status.filing_status_user_id = '2'
    AND status.Statustype = 'Live'
    AND status.Currentstatus = 'Accepted'
    AND status.status_doc_id =
    document_main.document_main_doc_id
    AND users_account.account_id =
    document_main.document_main_company_account_id
    </CFQUERY>
    <CFQUERY NAME="getStuff" datasource="myDS"
    BLOCKFACTOR="100">
    SELECT
    users_account.client_name,
    FROM
    users_account
    WHERE
    account_id = '#getInfo.document_main_account_id#'
    AND account_type = 'Individual'
    </CFQUERY>
    The problem is that the account_id referred to in the
    users_account table can be either a Company or an Individual. So in
    my html table the output would list both. A co-worker suggested a
    UNION ALL and to alias the client_name fields. But that query seems
    to ignore the alias after the union.
    Can anyone help me out?

    Thanks for your help Dan.
    I added this to the query:
    CASE users_account.account_type
    WHEN 'Company' THEN users_account.client_name
    END AS COMPANYNAME,
    CASE users_account.account_type
    WHEN 'Individual' THEN users_account.client_name
    END AS IndiNAME
    The problem I have is that because of:
    AND users_account.account_id =
    document_main.document_main_company_account_id
    the output is empty for "IndiNAME".
    Users_account.account_id can refer to a record
    with"individual" or "company" as the account type. So in the same
    record in document_main, document_main_account_id refers back to an
    individual while document_main_company_account_id refers back to a
    company account.
    So of course if I change the above to:
    AND users_account.account_id =
    document_main.document_main_account_id
    then "COMPANYNAME" is empty in the output.
    I can't figure out how to get those two values without one or
    the other being empty (or breaking the link altogether from the
    document_main table to the users_account table).

  • HT1339 I have tried restoring an Ipod Nano 6th Generation but it seems to keep looping back and saying it is in recovery and needs restoring, can anyone help?

    I have tried restoring an Ipod Nano 6th Generation but it seems to keep looping back and saying it is in recovery and needs restoring, can anyone help?

    Try doing a level reformat of the iPod's flash storage instead to see if that kills the restore loop using the instructions in the article below.
    http://www.methodshop.com/gadgets/ipodsupport/erase/
    B-rock

  • I am trying to move a picture that I brought over from iWeb and it is locked. I need to move it. Can anyone help?

    I am trying to move a picture that I brought over from iWeb and it is locked. I need to move it. Can anyone help?

    It is probaly just "inline" ie part of the text.
    click on it > Inspector > Wrap > Floating
    Peter

  • I have forgotten my iPad password and tried to back up and restore my iPad but it says you need to unlock your device before you restore it but that is the whole reason I am trying to restore my iPad. Can anyone help?

    I have forgotten my iPad password and tried to back up and restore my iPad but it says you need to unlock your device before you restore it but that is the whole reason I am trying to restore my iPad. Can anyone help?

    Forgotten passcode or device disabled after entering incorrect passcode

  • My iphone is no longer working I have black screen with a picture of the itunes logo and a USB cable.  When I try to connect my iphone to itunes the device is not detected, can anyone help me? I desperatley need my phone back

    My iphone is no longer working I have black screen with a picture of the itunes logo and a USB cable.  When I try to connect my iphone to itunes the device is not detected, can anyone help me? I desperatley need my phone back

    I have had a 3GS for 2+ years.  After upgrading to IOS 4 (now 4.3.5) I began having problems.  In the past week, my screen went to the itunes logo and USB cable twice -- unprovoked -- just found it sitting there like that!  I connected to itunes and it did restore from a backup but it is a major inconvenience.  I am also searching for answers, but better back-up regularly!

  • I have been editing a document on my MacBook Pro and iPad, which has the newer versions of Pages. Now, I cannot open on My MacBook. It says I need a newer version of OS. However, I'm not showing a newer version being availabe!!! Can anyone help???

    I have been editing a document on my MacBook Pro and iPad, which has the newer versions of Pages. Now, I cannot open on My MacBook. It says I need a newer version of OS. However, I'm not showing a newer version being availabe!!! Can anyone help???

    That is Pages for iPad v2.0, which Pages '09 v4.3 can't read.
    You need to either stick with the older version of Pages on the iPad or get Pages 5 for the Mac which is only available if you are running OSX 10.9 Mavericks.
    Unfortunately that is not the end of your woes because Apple has made iCloud convert the files to Pages 5 now, and Pages 5 has over 90 features deleted on top of doing a shocking job of converting older Pages files.
    Peter

  • I need to export a photo at around 1meg file size,and dont seem to be able to do it in the presets can anyone help please ,I shoot on a canon 5d

    I need to export a photo at around 1meg file size,and dont seem to be able to do it in the presets can anyone help please ,I shoot on a canon 5d

    I believe Frank is referring to the end use (e.g., for print or on-screen use).
    Until he returns, I can tell you that I ran a quick test using an image from the Aperture 3 training book library which was as follows:
    Camera = Canon EOS 5D Mark II
    Master resolution = 5616 x 3744 (21 MP)
    I was able to export to a JPEG with end file size of 1 MB as follows:
    Export Presets drop-down > select 'Edit' option
    Selected preset name 'JPEG - 50% of Original Size' > change percentage value to 40% > change DPI value to '300' > click OK to set as current default > Export version to desktop.
    The exported JPEG has a resolution of 2246 x 1498 and appears on screen to have the same image quality of the original in Aperture.
    Note - I did not change the default Image Quality slider in the Export Preset dialog (which left it at 10).
    Basically, you will need to play around with the settings until you find the appropriate values to arrive at an image version you want.

  • Can anyone help me change the DOB on my sons profile for his apple I'd so I can setup family sharing? I originally put both ids in my name. He is 19 do it keeps saying needs my permission but no instructions in how to get that done?

    Can anyone help me change the DOB on my sons profile for his apple I'd so I can setup family sharing? I originally put both ids in my name. He is 19 do it keeps saying needs my permission but no instructions in how to get that done? His phone was stollen once last month need to get this done ASAP to prevent future headaches. Ty

    You can not change the date of birth on the account. Apple makes that clear up front when the account is created.
    The only way to "fix" this is going to be for him to create a new account with the correct information. Any apps purchased with the old one will need to be re-purchased with the new account. They can not be transferred.

  • I need an e-mail sending to my macbook, it appears to download but is never in my inbox. It does got to my iphone.  It isn't in trash.  Can anyone help ?

    I need an e-mail sending to my macbook, it appears to download but is never in my inbox. It does got to my iphone.  It isn't in trash.  Can anyone help ?

    I get those all the time. Most annoying. I usually ignore them or mark them as spam.

Maybe you are looking for