Group by and then convert form Row to column

Hi All,
below is a transaction table for bank customer.
region_id     cutomer_id     transaction_type     transaction_date
101          12345          CC               10-March-2011
101          12345          DC               07-March-2011
101          12345          P1               01-March-2011
101          12345          p2               10-Jan-2011
102          45678          CC               15-feb-2011
101          12345          p3               27-OCT-2010with combinaton of region_id and customer_id, we get uniq record from the table. There are also different kind of transaction a customer has done. It is given in transaction_type column (CC - Credit card, Dc - Debit Card, and those start with P% {including P1, p2, p3} = payment).
Now my requirement is to get the number of transaction for each transaction type for a current year and also number of total transaction by the customer. Below is my output table.
region_id     cutomer_id     transaction_type     transaction_date     Tran_type_cc     Tran_type_DC     Tran_type_P     count_tran
101          12345          CC               10-March-2011          1          1          2          5
101          12345          DC               07-March-2011          1          1          2          5
101          12345          P1               01-March-2011          1          1          2          5
101          12345          p2               10-Jan-2011          1          1          2          5
102          45678          CC               15-feb-2011          1          0          0          1
101          12345          p3               27-OCT-2010          1          1          2          5if i do group by it gives me result but at row level and to convert row into column to get above result, i need to use decode function. My sourcec is containing 25 miliion records, and if i execute the query, it is getting hanged. Can someone help me how can i write a fine tuned query by using analytical function

How about this?
Note: I suppose, p1, P1, p2, P2, p3, P3 all belong to the same payment category regardless of their upper/lower case.
Here is the table and the data:
CREATE TABLE T1 (REGION_ID NUMBER, CUSTOMER_ID NUMBER, TRAN_TYPE VARCHAR2(5), TRAN_DATE DATE);
INSERT INTO T1 VALUES (101, 12345, 'CC', TO_DATE('10-Mar-2011','DD-MON-YYYY'));
INSERT INTO T1 VALUES (101, 12345, 'DC', TO_DATE('07-Mar-2011','DD-MON-YYYY'));
INSERT INTO T1 VALUES (101, 12345, 'P1', TO_DATE('01-Mar-2011','DD-MON-YYYY'));
INSERT INTO T1 VALUES (101, 12345, 'p2', TO_DATE('10-Jan-2011','DD-MON-YYYY'));
INSERT INTO T1 VALUES (102, 45678, 'CC', TO_DATE('15-FEB-2011','DD-MON-YYYY'));
INSERT INTO T1 VALUES (101, 12345, 'p3', TO_DATE('27-OCT-2010','DD-MON-YYYY'));Here is the query:
SELECT REGION_ID, CUSTOMER_ID, TRAN_TYPE, TRAN_DATE
  , SUM(DECODE(TRAN_TYPE, 'CC', '1','0')) OVER (PARTITION BY CUSTOMER_ID) AS CC
  , SUM(DECODE(TRAN_TYPE, 'DC', '1', '0')) OVER (PARTITION BY CUSTOMER_ID ) AS DC
  , SUM(DECODE(SUBSTR(UPPER(TRAN_TYPE), 1,1) , 'P', '1','0')) OVER (PARTITION BY CUSTOMER_ID) AS P
  , SUM(1) OVER (PARTITION BY CUSTOMER_ID) AS TRAN_T
FROM T1 ;
r_id   cust_id      t_TYPE   T_DATE  CC_CNT  DC_CNT  P_CNT  T_CNT
101     12345     CC     10-MAR-11     1     1     3     5
101     12345     DC     07-MAR-11     1     1     3     5
101     12345     p3     27-OCT-10     1     1     3     5
101     12345     p2     10-JAN-11     1     1     3     5
101     12345     P1     01-MAR-11     1     1     3     5
102     45678     CC     15-FEB-11     1     0     0     1Edited by: PhoenixBai on Mar 14, 2011 4:16 PM

Similar Messages

  • What product will allow me to place a watermark on a picture of a painting and then convert it to a PDF?

    What product will allow me to place a watermark on a picture of one of my paintings, and then convert it to a PDF for use on my website?

    Photoshop, etc.
    What you describe is trivial.  Practically any graphics software can do that.

  • Do I still have to save the PDF first in my file then retrieve it in Adobe and then convert?

    When I receive a document do I first have to save it in my computer then go into abobe, then load it in there and then convert to a doc?

    Hello,
    1) Launch Adobe Reader X
    2) Click on "Edit" on Meu Bar and click on "Preferences"
    3) Go to the option "Internet" from left hand list
    4) Make sure "Display PDF in Browser is checked"
    5) Save the changes and close Reader X
    Screenshot attached :
    Then try to view any PDF in browser.
    Thanks
    Vikram

  • How can I add three binary numbers and then convert to string (Hex format)?

    Hi All,
    I have my problem "half" resolved, but need some assistance on the final piece.  Overall, I need to take three string values (hex format), convert them to binary, add them and then convert back to a string (hex format).  If that doesn't make sense maybe this will:
    Final Result (My target) = 0xCC
     = 0x03 + 0x01 + 0x04
              = 0x03; 0011b
              = 0x01; 0001b
              = 0x04; 0100b
    For my app, we are dropping "masking" some of the bits so that we get 1 byte:
              = 0x03; 11b
              = 0x01; 001b
              = 0x04; 100b
    So...
    11001100b = 0xCC
    In my VI, I am taking each initial string [0x03,0x01 and 0x04] type casting them to U8.  Next I need to "mask" the binary values as shown above and then add them.  I am not sure how to do this in LV??
    Thanks for the help,
    Bryan

    Hi Bryan,
    there's a conversion palette in the string palette, ever looked at those functions?
    The rest is pure simple math:
    It's the straight-forward way, there are other possibilities too!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • I built an ad using layers saved it and then converted it to a jpeg. Now when I go into elements 11 to do anything else it will not allow to copy and paste to create a new layer. What am I missing?

    I built an ad using layers saved it and then converted it to a jpeg. Now when I go into elements 11 to do anything else it will not allow to copy and paste to create a new layer. What am I missing?

    You know that you lost the layers when you saved it as a jpeg, right? But you're saying you can't add layers to the jpeg now when it's open in the editor? Go to Image>mode and be sure it's RGB, for starters. Are all the commands in the Layer menu grayed out?

  • Tool for creating UML and then convert to Java code?

    Hi,
    Does anyone have a suggestion for a free tool that allows for the creation of UML diagrams and then converting it to Java code?

    Try the Omondo plugin for eclipse: http://www.eclipseuml.com. I would rather use it or buy MagicDraw than work with Poseidon -- terribly terribly slow even on gigaherz PCs... :(

  • Should i necessarily first have a .h and then convert it to a .dll?

    hi.
    i want to use windows 98 APIs.
    but i recieve a linker error. i've see many
    JNI example that convert a header file to a .dll
    but is windows we have .DLLs not header!?
    should i necessarily first have a .h and then
    convert it to a .dll?
    it's my code:
    public class JNItest
    long returnValue;
    static
    System.loadLibrary("user32");
    public native long EmptyClipboard();
    public void free()
    returnValue = EmptyClipboard();
    public static void main(String args[])
    new JNItest().free();
    I SET THE PATH OF SYSTEM DIRECTORY OF WINDOWS FOR LINKER TO FIND
    USER32.DLL BUT I RECIEVE THIS ERROR:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: EmptyClipboard
    at JNItest.EmptyClipboard(Native Method)
    at JNItest.play(JNItest.java:14)
    at JNItest.main(JNItest.java:18)
    please help.
    thanks a world.

    You can't call EmptyClipboard directly from your Java code.
    You need to run javah against that source file. It will generate a C++ header file with the definition of the native method you declare in your Java file. You create a C++ DLL that includes that header file and implement that stub function in C++. It will simply call the Win32 EmptyClipboard function.
    Then, you add a line in your Java source to loadLibrary the new DLL after User32, and it should work. See the JNI tutorial for details.
    Tim

  • Sharing iTunes and then using Front Row

    I have been downloading all the album artwork just like everyone else is, now that iTunes 7 is out.
    I have run across a small problem and a fix I would like to pass along for people having problems viewing the album artwork on a computer that is sharing the iTunes from another computer and then using Front Row.
    First off, the artwork for me seems to work fine on all individual computers that have the songs and the album artwork on it.
    When I shared my 'master or main' computer iTunes with my Mini Mac Intel, I then played the music using Front Row but the majority of the album covers would not show up.
    For some reason only a few of the album covers were showing up in Front Row on the shared computer. It took me quite awhile to figure out that the only album covers that were showing up were the album covers that I dragged and copied onto the main computers iTunes album window.
    I don't know if anyone has found anything easier to fix this problem but I went ahead a copied all of the album artwork, one by one, on the main computer into the iTunes artwork window. Now, all the computers that access the main computer via sharing, shows the album artwork when using Front Row.
    I hope I explained this clear enough.
    Here is a photo of my Mac Mini hooked up to my TV, playing Front Row and using the shared iTunes Library from my main computer which is an iMac G5.
    http://users.sisqtel.net/jkriz/MacMini/frontrow_albumcovers.jpg
    I needed to use the flash for this photo because it was getting dark but I think you get the idea.
    I know I could have put all my music on the Mini Mac or any of my other computers and I wouldn't have had to go through all of this... but then I would have trouble keeping all of my computers music up to date. This way, I only have to keep the main computer up to date with all of my music. Much easier.
    If anyone has any other suggestions, please let me know.
    I hope the rest of you can benefit from this tip.
    iMac 17 (Intel), iMac G5 (Rev B), Mac Mini (Intel)   Mac OS X (10.4.5)  

    Bizmarck,
    Well, this is interesting.
    When I first read your question I said to myself, of course I can play the shared slideshow along with the selected shared music.....
    Well, I'm glad I tried it out first before I posted this as I cannot play the selected songs on the shared slideshow. All I could play was the Minuet in "G"....
    I could have sworn I used to be able to do this with 10.4.7 and Front Row 1.2
    However, I could be wrong.
    I have tried everything.
    I have the Serving computers iTunes and iPhoto open and to allow sharing of both.
    On the Mac Mini which is playing the shared items from the serving computer, I can turn off the music but I cannot select a song from the shared library in iPhoto. All the library shows for music selection on the Mac Mini is the music that is on the Mac Mini.
    Apparently Apple has more work to do if this is going to work.
    It is interesting to me that we cannot play a shared slideshow along with the shared music that was selected with that slideshow.
    If the selected song from the shared slideshow is already on the Mac Mini, then I can choose it, but I cannot choose any other songs unless they are on the Mac Mini.....
    It seems that Front Row will not play the selected shared song from the shared slideshow. Front Row only wants to play the songs that are on the Mac Mini for any of the shared slideshows... BUMMER.......
    If you open iPhoto (not Front Row) on the Mac Mini, then select a shared slideshow, then click on the 'Play' button. You will see that Minuet in "G" is selected to play on that shared slideshow. I turned all of mine OFF for the time being as I am tired of the sample music also.
    If I come up with anything new I will post it here.
    Thanks for sharing this information.

  • How do you save your DVD to your Hard Drive, and then convert to iPod?

    Hello everyone, I was wondering how you save your DVD to your hard drive and then convert it to the iPod Video.
    Please respond.
    P.S.
    I know that it's been discussed all the time, but none of the posts are useful for me.
    Thanks

    Hi,
    The best option is to pull the card out and plug to your computer UNLESS your computer does not have a card reader. If your computer did not have a card reader, you need to map the cardreader on your printer to your network using the following method:
        http://h10025.www1.hp.com/ewfrf/wc/document?lc=en&dlc=en&cc=us&docname=c00149194
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Combining avi file with subtitle file and then converting to ipad

    So I'm trying to convert my avi files into my ipad but before that I need to combine its subtitle file with its avi file first. Does anyone know how to do this?
    I need to combine an avi file with its subtitle file and then convert it into an mp4 and transfer it to my ipad. I need to steps. Thanks!

    Handbrake
    Roadmovie
    Do some research and pick one

  • Ascii to PDF using word or PDF template and then converting the pdf to a PDF form

    Hi all,
    We are planning to restructure the whole PDF generation process in our application.. We use ASCII files to provide the data feed..Is it possible to create PDF files out of them with a pre defined Template and then to make that PDF editable with some form fields.. ??Is PDF generator capable of handling this or should we be looking for some other livecycle product..?? Kindly help us in this regard..

    The Process goes like this:
    ASCII file for data feed ----> template file -----> PDF file with form fields generated.. ---> Reader extention rights given to the Form fields for the end users to save the forms using Adobe reader..
    Thanks.

  • How can I store a form name with path and then call form from a table

    Is it possible that any form that I built I store that form in some table in DB and then call that form from table, if yes, then how can i get this functionality. I am not very experience in form and do not know if it can be done because i think if it is possible then this can be a good security for application and easy to handle as well.
    Thanks in advance
    Maz

    If you have a Forms block based on this table:
    declare
      module varchar2(100);
    begin
      module := :block.column;
      call_form ( module ) ;
    end;If you don't have any blok based on that table
    declare
      module varchar2(100);
    begin
      select  module_name
      into module
      from ...
      where ...
      call_form ( module ) ;
    end;Francois

  • Oracle 8i vs Oracle 9/10: Group by and order of returned rows

    Hello people,
    I've searched the forum for threads on this topic: the order of returned rows in queries which have a GROUP BY clause, and found out that Oracle states that GROUP BY clause does not guarantee that the order of returned rows will be the same every time nor the rows will be ordered someway. I've confirmed this information in the Oracle documentation for the GROUP BY clause for Oracle 9 and 10. But I couldn't find the same in the Oracle 8 documentation (SQL Reference), in which the GROUP BY clause section does not mention anything about the order of returned rows in queries which have a GROUP BY (except for something about using a GROUP BY and a HAVING clause together, which is not helpful in this situation).
    Besides, I have an Oracle training book: "Introduction to Oracle: SQL and PL/SQL" for Oracle 8, where the GROUP BY clause is said to perform a default ordering, here is the text:
    "By default, rows are sorted by ascending order of the columns included in the GROUP BY list. You can override this by using the ORDER BY clause".
    So, I need to find out if Oracle 8 GROUP BY clause did some kind of sorting over the returned rows as it is said in the training book and if this behavior changed in Oracle 9. And more important: where to look for to find documentation about this change.
    Thank you, guys, I really hope someone could help me with this.
    Fer.

    And this statement from Tom (taken from the link above) says more about why the sort (even when done because of group by) should not be relied upon:
    <quote from="asktom link above">
    and even when it does sort as a by product of its processing, the sort is a
    BINARY SORT, not your sort (with your language and character set)
    </quote>

  • SQL help, how to group by column A and then get top frequency of column B?

    Assuming the following table, operation represents each kind of transaction operation
    table operation employee other column c
    '<' id1
    '<' id1
    '<' id2
    '*' id3
    '/' id1
    question, for each operation, which employee do the most? which employee do the 2nd most?
    I thought I need to group by operation first, and then get the frequency of employee, and get the top 1 or top 2 frequency highest.
    But I am stuct, and do not know how to write the sql.

    998408 wrote:
    Assuming the following table, operation represents each kind of transaction operation
    table operation employee other column c
    '<' id1
    '<' id1
    '<' id2
    '*' id3
    '/' id1
    question, for each operation, which employee do the most? which employee do the 2nd most?
    I thought I need to group by operation first, and then get the frequency of employee, and get the top 1 or top 2 frequency highest.
    But I am stuct, and do not know how to write the sql.Welcome to OTN. Ops! posted in wrong forum. Just post in {forum:id=75}. Before posting there close this thread marking as answered.
    If someone's response is helpful or correct, please mark it accordingly.*

  • How do you test if a string could be a valid int and then convert to int?

    Hello, my name is Esran41 and I'm new to this site. I'm in computer science one this year and our current assignment is to make a console based Tic-Tac-Toe game. The final program must be able to detect errors in the user's input. For example, if the program asked the user for an int and he typed a character, our program must recognize this, print an error message, and then prompt him for the int again. I also need to know some common string manipulation methods(like String.length) and their syntax too. Again, I'm extremely new to java, so please include code fragments and example programs to demonstrate these methods.
    To sum-it-up, I need to know how to do the following(The syntax):
    Method (1)
    - test an inputed string to see if it's a valid integer
    - report an error to the user if it's not a valid integer
    - if there was an error, prompt the user again
    Method (2)
    - Pass the inputed string as a parameter
    - Convert the string into an integer
    - return the integer
    Also, what is a try-catch statement, what does it do, and how is it implemented?
    Please post any advice or help that you may have pertaining to my problems.
    Thanks!

    Do not insult me. If I could read my computer science
    book, I would. Please don't insult yourself... by pointing out your limitations...
    I will apologize for my cynical remarks... You should see how many requests for " I need help" where the answer could be found so easily...
    But it is quite obvious that you have access to the internet... If you did a search for Java, eventually you would find yourself as Sun's web site... Which means that you would have arrive at this page...
    http://java.sun.com
    and towards the bottom left had corner of that page you would find these links...
    Learning
    New to Java Center
    - Tutorials & Code Camps
    - Online Sessions & Courses
    - Course Certification
    - Instructor-Led Courses
    - Quizzes
    And you will find the same resources that I am using to learn Java...
    I'm looking up this information not only for myself, but for my class too....
    Thus, we are stuck with old computers, about twenty books for 220 kids, and one teacher who is great at >C++, but knows nothing about java.Then print out the Java documentation, goto Kinko's and make copies so that your class can have the reference material available to them, or ask your teacher to... Since he/she will need to learn the language also... But since they have programming experience they will be better able to explain the concepts of programming that you do not understand...
    You can make any excuse for why it is difficult for you to learn, but in the end its totally irrelevant... If the school district cannot provide funding for class material, then instead of complaining with " I don't have a book... " start a community fund raiser to purchase those materials... Goto to the public library and see if they have resources you and your class can utilize... After all, it is your responsibility to educate yourself...
    And most important of all, never ever say anything negative or limiting against yourself...
    Do not insult me. If I could read my computer science book, I would. This is a statement against yourself... What does this statement tell you about yourself... You stated that I should not judge, but here you made a judgement about your own ability to learn...
    To even insinuate that I skip class is an outrage to me. You should watch your tongue and not be so >quick to judge a situation.Why, do you ? Apparently I touched a nerve somewhere... But that does not matter...
    Are you really concerned with what I think of you... If you are then you are a fool...
    What other think or say have nothing to do with you... Do you know me, do I know you...
    The answer is clear... I can give it to you... The Answer is No.
    If you want to learn then learn... Read, Research, Practice and Read again... So simple...
    Anyway... Have fun... Check out the tutorials, learn how to use the API documentation and practice coding...
    and here are those links again...
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Essentials of the Java Programming Language: A Hands-On Guide, Part 1 and 2
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/
    Language Essentials Short Course
    http://java.sun.com/developer/onlineTraining/JavaIntro/contents.html
    Others
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Tutorial Index
    http://java.sun.com/developer/onlineTraining/index.html
    - MaxxDmg...
    - ' He who never sleeps... '

Maybe you are looking for

  • Display an Alert message in PL/SQL block in APEX

    Hi, we are getting an oracle exception while inserting a new row. As it is having the unique constaint on a coulumn. Now the problem iis we need to Display an "Alert message" based on the input field validation. That java script code for alert has to

  • Can I split my iTunes library between 2 hard drives?

    Can iTunes library be split between to hard drives? Hi, My laptop has 2 x 250GB internal hard drives. I wish there was 1 x 500 GB one. 1 of them is nearly full with music only 2GB remaining and the other one has over 100GB remaining. I'm wondering is

  • It's very urgent please help me Hoe to check role given for each user....

    Hi All, I have aquery like i have I have FBV0 tcode, I used SUIM to generate a list of users that has access to it. from the list that I have, I want to know who among them has the access to display or update how can I determine that? Could any one o

  • Swap background image?

    Hi, I am looking for a posibility to dynamicaly change the background image of a vi. See attached example: The switch should change the circle-image into a box-image. the two images are overlaid and I thought I could make one image visible and the ot

  • Compress PDF Files

    Is there a way to compress large PDF files into smaller PDF files with acrobat software? When I scan a 2 page text document it is sometimes 2 MB.