Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT

Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT. Below SQL is an example of what I am trying to do - In this case instead of using JOIN, can I have three pivot_for_clauses in the same sql?
SQL:
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
FROM (SELECT company_id,action_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id) IN ((1) as num_logins,(2) as num_logouts,(61) as
num_logins_from_mobile_device,(16) as num_pref_changed,....)) P1
JOIN
(SELECT company_id,action_type_id,tx_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice, (4,4) AS
edit_invoice,(3,3) as num_checks,(3,47) as num_paychecks,(3,7) as num_recvd_payments,(3,9) as num_bills,
(3,35) as num_estimates,(3,46) as num_purchase_orders)) P2
on P1.company_id=P2.company_id
JOIN
(SELECT company_id,action_type_id,list_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,(3,1) as
num_accounts,(3,4) as num_employees,(3,6) as num_customers,(3,14) as num_memorized_reports)) P3
on P2.company_id=P3.company_id
left outer JOIN
(SELECT company_id,create_date,count(*) as num_logos
FROM qbo.companylogos_1 group by company_id,create_date having trunc(create_date)=trunc(sysdate)-1) P4
on P3.company_id=P4.company_id
ORDER BY P1.company_id) source
ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))WHEN MATCHED THEN
UPDATE SET dest.num_items = source.num_items where 1=2
WHEN NOT MATCHED THEN
INSERT (dest.company_id,.....) values (source.company_id,.....);

Maybe
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
         FROM (select *
                 from (SELECT company_id,action_type_id
                         FROM Testauditinfo_1
                        where trunc(audit_date_time) = trunc(sysdate)-1
                      ) a
                      PIVOT (count(action_type_id)
                        FOR (action_type_id) IN ((1) as num_logins,
                                                 (2) as num_logouts,(61) as num_logins_from_mobile_device,
                                                 (16) as num_pref_changed,....
              ) P1
              JOIN
              (select *
                 from (SELECT company_id,action_type_id,tx_type_id
                         FROM Testauditinfo_1
                        where trunc(audit_date_time) = trunc(sysdate)-1
                      ) a
                      PIVOT (count(action_type_id)
                        FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice,
                                                            (4,4) AS edit_invoice,
                                                            (3,3) as num_checks,
                                                            (3,47) as num_paychecks,
                                                            (3,7) as num_recvd_payments,
                                                            (3,9) as num_bills,
                                                            (3,35) as num_estimates,(3,46) as num_purchase_orders
              ) P2
           on P1.company_id = P2.company_id
              JOIN
              (select *
                 from (SELECT company_id,action_type_id,list_type_id
                         FROM Testauditinfo_1
                        where trunc(audit_date_time) = trunc(sysdate)-1
                      ) a
                      PIVOT (count(action_type_id)
                        FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,
                                                              (3,1) as num_accounts,
                                                              (3,4) as num_employees,
                                                              (3,6) as num_customers,
                                                              (3,14) as num_memorized_reports
              ) P3
           on P2.company_id = P3.company_id
              left outer JOIN
              (SELECT company_id,create_date,count(*) as num_logos
                 FROM qbo.companylogos_1
                group by company_id,create_date
                having trunc(create_date) = trunc(sysdate)-1
              ) P4
           on P3.company_id = P4.company_id
        ORDER BY P1.company_id
      ) source
   ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))
WHEN MATCHED
THEN UPDATE SET dest.num_items = source.num_items where 1 = 2
WHEN NOT MATCHED
THEN INSERT (dest.company_id,.....)
      values (source.company_id,.....)Did you try it ?
Regards
Etbin

Similar Messages

  • How can I use multiple row insert or update into DB in JSP?

    Hi all,
    pls help for my question.
    "How can I use multiple rows insert or update into DB in JSP?"
    I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
    With thanks,

    That isn't true. Different SQL databases have
    different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
    I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
    and there are also a lot of different ways of talking to
    SQL databases that are possible in JSP, from using
    plain old java.sql.* in scriptlets to using the
    jstlsql taglib. I've done maintenance on both, and
    they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
    Well, sure. As long as you only want to update rows
    with the same value in column 2. I had the impression
    he wanted to update a whole table. If he only meant
    update all rows with the same value in a given column
    with the same value, that's trivial. All updates do
    that. But as far as I know there's know way to update
    more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
    Unless you're using MySQL, for instance. I only have
    experience with MySQL and M$ SQL Server, so I don't
    know what PostgreSQL, Oracle, Sybase, DB2 and all the
    rest are capable of, but I know for sure that MySQL
    can insert multiple rows while SQL Server can't (or at
    least I've never seen the syntax for doing it if it
    does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
    Don't assume that all SQL databases are the same.
    They're not, and it can really screw you up badly if
    you assume you can deploy a project you've developed
    with one database in an environment where you have to
    use a different one. Even different versions of the
    same database can have huge differences. I recommend
    you get a copy of the O'Reilly book, SQL in a
    Nutshell. It covers the most common DBMSes and does a
    good job of pointing out the differences.Yes, I understand that.
    It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
    I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
    The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing.

  • Can we use hints in oracle 11g version ?

    can we use hints in oracle 11g version ? is it working ??

    Why do you ask these questions? Have you looked at the SQL Reference Guide and Performance Tuning Guide for your Oracle version - both which covers using hints?
    Have you see a statement that is not supported? Or does not work?
    Or are you simply doing idle speculation and expecting forum members to spend their free time in answering a basic question where the answer is ridiculously simply to find?

  • Can I use multiple iPhones on the same iTunes account? e.g. my wife and I each have iPhones

    can I use multiple iPhones on the same iTunes account? e.g. my wife and I each have iPhones

    Yes, you can have as many devices - iPhones, iPods, iPads - as you like using the same iTunes account.

  • Can i use multiple icloud accounts on 1 device

    Can I use multiple icloud email accounts on one device?

    Yes, you could have multiple iCloud accounts for Mail, Contacts, Calendars, Reminders, Safari, Notes, and Find My iPhone, but only one primary iCloud account for Photo Stream, Documents & Data, and Storage & Backup.

  • Can i use multiple icloud accounts in my find my iphone app?

    Can i use multiple icloud accounts in my find my iphone app? I have multiple accounts that i want to tie to that app.

    You can't buy another one.  You have to reuse one of the accounts previously set up on your phone, or create a new one to use on another iOS device (running iOS 5 or higher) or Mac (running OS X 10.7.2 or higher), if you have one.

  • How Can I Use Multiple Weblogic Instances in a Single OS

    Hello Everyone,
    Actually I have to install Some different applications. Few of them need weblogic 10.3.6 and others need 10.3.4. The OS am using is Oracle  Enterprise Linux 5.
    Now I am able to install 2 separate(One of 10.3.4 and 10.3.6) instances with two different users,In two different directories.
    I have installed the weblogic 10.3.6 version with a user webadmin and installed node manager with port 5556. This is working fine.
    The main problem here is :
    In the second instance (10.3.4 ) installed with a a different user and gave the port number to NodeManager as 1600 and its not getting started. Its throwing error and also after some errors in the terminal am able to see that its reverting to port number 5556 only.
    What might be the issue?
    I have to install 2 different versions of weblogic in a single Server. But am failing with NodeManager. What Can I do to have multiple weblogic instances with multiple versions in a single server ?
    Can anyone suggest a resolution for this please ?
    Thanks in advance.

    Pl do not spam these forums with multiple posts - How Can I Use Multiple Weblogic Instances in a Single OS

  • Can you use multiple plugins on one piece of media?

    can you use multiple plugins on one piece of media?
    ...so for example have one plugin for a UI control bar, another for tracking, and another for advertising?
    If this is possible how? What types of plugin would each plugin be and what sort of media element would be required?
    Or is this not the correct approach? If not what would the correct approach be?
    Thanks in advance for support.

    I have got this plugin to set it's proxiedElement.
    To do so, I needed to follow David_RealEyes advice too.
    But I still can not acheive what I set out to find out, all I was trying to do was trace the current time of the videoElement, to begin to understand how plugins work. Can anyone advise please? Thanks in advance for support.
    I thought to acheive this I would just need to add  a listener for like this:
    dispatcher.addEventListener(TimeEvent.CURRENT_TIME_CHANGE,  onTimeChange);
    Then write the function like this:      
    private function onTimeChange(e:TimeEvent):void
                 trace('**********onTimeChange: '+ e.time)
    ...But this doesn't work.
    What am I doing wrong?
    Here's the class now for the TraceListenerProxyElement
    package
        import org.osmf.elements.*;
        import org.osmf.events.*;
        import org.osmf.media.*;
        import org.osmf.metadata.*;
        import org.osmf.traits.*;
        public class TraceListenerProxyElement extends ProxyElement
            public function TraceListenerProxyElement(wrappedElement:MediaElement)
                trace('TraceListenerProxyElement')
                super(wrappedElement);
            // Overrides
            override public function set proxiedElement(value:MediaElement):void
                trace('override set proxy')
                trace('value: ' + value)
                if(value)
                   super.proxiedElement = value;
                   trace('proxied element set')
                   enableListeners()
                super.proxiedElement = value;
                trace('proxied el: ' + proxiedElement)
            private function enableListeners():void
                trace('enableListeners')
                dispatcher = new TraitEventDispatcher();
                dispatcher.media = proxiedElement;
                dispatcher.addEventListener(AudioEvent.MUTED_CHANGE, processMutedChange);
                dispatcher.addEventListener(AudioEvent.PAN_CHANGE, processPanChange);
                dispatcher.addEventListener(AudioEvent.VOLUME_CHANGE, processVolumeChange);
                dispatcher.addEventListener(BufferEvent.BUFFER_TIME_CHANGE, processBufferTimeChange);
                dispatcher.addEventListener(BufferEvent.BUFFERING_CHANGE, processBufferingChange);
                dispatcher.addEventListener(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE, processDisplayObjectChange);
                dispatcher.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE, processMediaSizeChange);
                dispatcher.addEventListener(DRMEvent.DRM_STATE_CHANGE, processDRMStateChange);
                dispatcher.addEventListener(DynamicStreamEvent.AUTO_SWITCH_CHANGE, processAutoSwitchChange);
                dispatcher.addEventListener(DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE, processNumDynamicStreamsChange);
                dispatcher.addEventListener(DynamicStreamEvent.SWITCHING_CHANGE, processSwitchingChange);
                dispatcher.addEventListener(LoadEvent.BYTES_TOTAL_CHANGE, processBytesTotalChange);
                dispatcher.addEventListener(LoadEvent.LOAD_STATE_CHANGE, processLoadStateChange); 
                dispatcher.addEventListener(PlayEvent.CAN_PAUSE_CHANGE, processCanPauseChange);
                dispatcher.addEventListener(PlayEvent.PLAY_STATE_CHANGE, processPlayStateChange);
                dispatcher.addEventListener(SeekEvent.SEEKING_CHANGE, processSeekingChange);
                dispatcher.addEventListener(TimeEvent.COMPLETE, processComplete);
                dispatcher.addEventListener(TimeEvent.DURATION_CHANGE, processDurationChange);
                dispatcher.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onTimeChange);
                proxiedElement.addEventListener(MediaElementEvent.TRAIT_ADD, processTraitAdd);
                proxiedElement.addEventListener(MediaElementEvent.TRAIT_REMOVE, processTraitRemove);
            private function onTimeChange(e:TimeEvent):void
                trace('**********onTimeChange: '+ e.time)
            private function processAutoSwitchChange(event:DynamicStreamEvent):void
                trace("autoSwitchChange", event.autoSwitch);
            private function processBufferingChange(event:BufferEvent):void
                trace("bufferingChange", event.buffering);
            private function processBufferTimeChange(event:BufferEvent):void
                trace("bufferTimeChange", event.bufferTime);
            private function processComplete(event:TimeEvent):void
                trace("complete");
            private function processCanPauseChange(event:PlayEvent):void
                trace("canPauseChange", event.canPause);
            private function processDisplayObjectChange(event:DisplayObjectEvent):void
                trace("displayObjectChange");
            private function processDurationChange(event:TimeEvent):void
                trace("durationChange", event.time);
            private function processLoadStateChange(event:LoadEvent):void
                trace("loadStateChange", event.loadState);
            private function processBytesTotalChange(event:LoadEvent):void
                trace("bytesTotalChange", event.bytes);
            private function processMediaSizeChange(event:DisplayObjectEvent):void
                trace("mediaSizeChange", event.newWidth, event.newHeight);
            private function processMutedChange(event:AudioEvent):void
                trace("mutedChange", event.muted);
            private function processNumDynamicStreamsChange(event:DynamicStreamEvent):void
                trace("numDynamicStreamsChange");
            private function processPanChange(event:AudioEvent):void
                trace("panChange", event.pan);
            private function processPlayStateChange(event:PlayEvent):void
                trace("playStateChange", event.playState);
            private function processSeekingChange(event:SeekEvent):void
                trace("seekingChange", event.seeking, event.time);
            private function processSwitchingChange(event:DynamicStreamEvent):void
                trace("switchingChange", event.switching);
            private function processVolumeChange(event:AudioEvent):void
                trace("volumeChange", event.volume);
            private function processDRMStateChange(event:DRMEvent):void
                trace("drmStateChange", event.drmState);
            private function processTraitAdd(event:MediaElementEvent):void
                trace("Trait Add: " + event.traitType);
            private function processTraitRemove(event:MediaElementEvent):void
                trace("Trait Remove: " + event.traitType);
            private var dispatcher:TraitEventDispatcher;

  • Can we use multiple queries on one template

    Can we use multiple queries on one template

    Hi,
    if you're using data templates for your data set, you
    can put multiple queries in the XML data template.
    The queries may then be linked (or not) by the "link
    name" tag ...
    Grtz.Following you answer here...do you know eventually how/if possible to preview a report (with XMLP Desktop) that is using data templates for the data set?
    Thanks,
    Liviu

  • Can I use multiple Apple store gift cards per transaction or is it has to be one gift card per transaction?

    Can I use multiple Apple store gift cards (£25 each) per transaction or is it has to be only one gift card per transaction?? Does anyone know thanks

    Hola, Eddy
    notice that you have posted to an old thread (Oct-Nov2013) that actually took quite some time to get attention back then**
    I recommend that you contact the Store Group regarding your purchase question - don't let the "iTune-ish" URL and page title throw you off... it's the right place
    Store Group - Contact Us - Apple Support
    ** next time you have a question, I advise to check the dates carefully and if older than a month or so, AND it has no answer to your specific issue, start a NEW Question. You did a fine job of stating your exact issue - many folks, not so much.
    buenos dias
    CCC

  • Can I use multiple credit cards with family sharing

    My kids are adults.  Can I use multiple credit cards in family sharing so they can pay for their own purchases?

    Hello Cwb1234,
    Thank you for using Apple Support Communities.
    From what I understand, you want to set it up that your kids use their own credit cards for purchases within Family Sharing. Take a look at the article linked below, it outlines purchases and payments for Family Sharing and may offer a solution to the issue that you’re running into.
    Family purchases and payments - Apple Support
    Making purchases
    After you set up your family, any time a family member initiates a new purchase it will be billed directly to your account unless that family member has gift or store credit. First, their store credit will be used to pay the partial or total bill. The remainder will bill to the family organizer's card. As the family organizer, any receipts generated by the transaction will be sent to you. Learn more about how iTunes Store purchases are billed.
    Once paid for, a purchased item is added to the account of the family member who initiated the purchase. In other words, the content belongs to them, much as it would if you were buying them a book or a DVD. If Family Sharing is ever disabled, each member will keep the purchases they initiated, even though they were paid for by the family organizer.
    These are the only current options for payment within Family Sharing.
    Regards,
    Jeff D. 

  • Can I use multiple p class="logos" tag with the same name within the same html page?

    I was told not to use <div class> tags too many times. I was using them for text, images, to clear floats, I basically built my website using multiple <div class> tags. So if I can't use multiple <div class> tags could I use <p class> tags multiple times in the same html page?
    I have a string of logos at the bottom of my webpage which will all be using the same css characteristics for all logos. Would this be the proper way to write the code:
    HTML
    <p class="logos">Logo1<a href="...></a></p>
    <p class="logos">Logo2<a href="...></a></p>
    <p class="logos">Logo3<a href="...></a></p>
    <p class="logos">Logo4<a href="...></a></p>
    <p class="logos">Logo5<a href="...></a></p>
    <p class="logos">Logo6<a href="...></a></p>
    CSS
    .logos {
    margin-left:10px;
    Here's my website: http://www.darbymanufacturing.com/test_website/index.html - this is the website built with all div class tags
    I restarted the website in order to write the code properly so that I don't come to errors when uploading on the server like I am having with the website link above.

    Instead of writing something like this -
    <p class="logos">Logo1<a href="...></a></p>
    <p class="logos">Logo2<a href="...></a></p>
    <p class="logos">Logo3<a href="...></a></p>
    <p class="logos">Logo4<a href="...></a></p>
    <p class="logos">Logo5<a href="...></a></p>
    <p class="logos">Logo6<a href="...></a></p>
    Why not have something like this -
    <div id="logodiv">
    <p>Logo1<a href="...></a></p>
    <p>Logo2<a href="...></a></p>
    <p>Logo3<a href="...></a></p>
    <p>Logo4<a href="...></a></p>
    <p>Logo5<a href="...></a></p>
    <p>Logo6<a href="...></a></p>
    </div>
    with CSS like this -
    #logodiv p { ... }

  • Using table comparison can we use multiple tables as source?

    Using table comparison can we use multiple tables as source?
    Thank you very much for the helpful info.

    Table Comparison
    1) Input Data coming in
    2) Comparison table (table to which the data is compared)
    3) Output (input rows with respective opcodes based on the comparison result of input dataset with the comparison table)
    If your question is whether table comparison can accept union/join of multiple table sources, you can achieve by using merge/query transforms and then feeding to table comparison. Here, you have to be careful about choosing the primary keys inside table comparison

  • Can I use Reports Server Queue PL/SQL Table API to retrieve past jobs ?

    Hi all,
    Can I use Reports Server Queue PL/SQL Table API to retrieve past jobs using WEB.SHOW_DOCUMENT from Forms ?
    I have reviewed note 72531.1 about using this feature and wonder if i can use this metadata to retrieve past jobs submitted by a user.
    The idea would be to have a form module that can filter data from the rw_server_queue table, say, base on user running the form, and be able to retrieve past jobs from Report Server Queue. For this, one would query this table and use WEB.SHOW_DOCUMENT.
    Is this possible ...?
    Regards, Luis ...!

    Based on that metalink note and the code in the script rw_server.sql, I am pretty sure that by querying the table you would be able accomplish what you want... I have not tested it myself... but it looks that it will work... you have the jobid available from the queue, so you can use web.show_document to retrieve the output previously generated...
    ref:
    -- Constants for p_status_code and status_code in rw_server_queue table (same as zrcct_jstype)
    UNKNOWN CONSTANT NUMBER(2) := 0; -- no such job
    ENQUEUED CONSTANT NUMBER(2) := 1; -- job is waiting in queue
    OPENING CONSTANT NUMBER(2) := 2; -- opening report
    RUNNING CONSTANT NUMBER(2) := 3; -- running report
    FINISHED          CONSTANT NUMBER(2) := 4; -- job has finished
    TERMINATED_W_ERR CONSTANT NUMBER(2) := 5; -- job has terminated with

  • About iPad iOS 4.2 beta Airplay can't use multiple speakers?

    About iPad airplay can't use multiple speakers?
    My iPad use the latest ios4.2 beta1 ,there is 3 airport express in my house.
    In iOS 3.2 I can use the App "Remote" to control 3 speakers perfectly,but "Remote" even can install in ios4.2 ,not use smoothly.
    After I upgrade iOS to 4.2, I can use Airplay to control each speaker without "Remote",but can't use multiple speakers at the same time. Is anyone like me?
    Is there have any other solution can fix this problem?
    Thanks!

    I completely agree with Tamara, if you are running iOS 4.2, then you should also realize that there are two aveanues for you to get questions answered
    1) the developer forums (there is a specific forum area for 4.2 questions, marked in a big red banner across the top saying something about confidentiality.)
    2) The bug reporting tool available to developers, noted at the top of the iOS 4.2 forum page. When you go there read the format intructions linked to at the top of the form to ensure you put it in the format that is required for formal developer bug reports.
    Jason

Maybe you are looking for

  • Who can I complain to about a new order being canc...

    Please can someone help me before I go totally insane!! On 14th March I placed an order online with BT for Phone & Broadband with free BT Sport and paying the line rental in advance with it due to go live on 30th March. Transfer date came and went wi

  • PL/SQL Numeric error

    hi everyone, i have created a report with parameter i need to pass multiple values to the report so i have written code using substr in after parameter form to allow multiple values but my problem is when i use value 111 Foreign Assignment,100 Irvine

  • Existing price-plan on new 'Open-SIM' iphone 4

    (first time on this forum, so would appreciate your help) I currently have a long-term contract with T-mobile, within the UK. I would like to purchase an 'unlocked' iphone 4 (the 16GB version) online from apple. Firstly, would my existing price plan

  • WM Process flow

    Hi, What are the settings are required for extending the WM module in our Plant. Could you please tetll me the process  flow and transaction code , movement types to be used in WM scenarios. Please do the needful. Thanks.

  • Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:

    Could anyone please explain me what is this error about Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer at timetablegen.MainFrame.jButton17ActionPerformed(MainFrame.java:1816) at timetablegen.MainFrame.access$21