How to use partition by instead of group by?

Hi,
I am having trouble using partition by clause in following case,
column other_number with null values contains 10 records in 'some_table'
5 records with date 11-01-2009, item_code = 1
5 records with date 10-01-2009, item_code = 2
This query returns all 10 records, (which suppose to return 2)
SELECT count (a.anumber) over (partition by TO_char(a.some_date,'MM'), a.item_code) AS i_count, a.item_code,
TO_char(a.some_date,'MM')
     FROM some_table
     WHERE to_char(a.some_date,'yyyy') = 2009
     AND a.other_number IS NULL
Works fine if I wrote like this,
SELECT count (a.anumber) AS i_count, a.item_code,
TO_char(a.some_date,'MM')
     FROM some_table
     WHERE to_char(a.some_date,'yyyy') = 2009
     AND a.other_number IS NULL
group by TO_char(a.some_date,'MM'), a.item_code
How to use partition by in this case?

Hi,
Almost all of the aggregate functions (the ones you use in a GROUP BY query) have analytic counterparts.
You seem to have already discovered that whatever values are returned by
an aggregate funcition using "GROUP BY x, y, z" can also be found with
an analytic function using "PARTITION BY x, y. z".
Aggregate queries collapse the result set.
The aggregate COUNT function:
SELECT    deptno
,         COUNT (*)   AS cnt
FROM       scott.emp
GROUP BY  deptno
;tells how many of the 14 employees are in each of the 3 departments.
So does the analytic COUNT function:
SELECT    deptno
,         COUNT (*) OVER (PARTITION BY deptno)   AS cnt
FROM       scott.emp
;but the first query produces 3 rows of output, the second query produces 14.
You could get 3 rows of output using the analytic function and SELECT DISTINCT , but it's inefficient.
Which should you use? Like so many other things, the answer depends on what data you have, and what results you want from that data.
If you want collapsed results (one row per group), that's a striong indication that you'll want aggregate, not analytic functions.
If you want one row of output for every row in the table, that's a strong indication that you'll want analytic functions.
If you have a particular question, ask it. Post some sample data and the results you want from that data, as Rob said.
There is another important difference between aggreate and analytic functions: analytic functions can easily be restricted to a window , or subset, of the data set. This is something like a WHERE clause, but a WHERE clause applies to the whole query: a wondowing condition applies only to an individual row.
If you need to compute a SUM of rows with an earlier order_date than this row or an average of the last 5 rows, then you proabably want to use analytic function.

Similar Messages

  • EREC - How to use link generated by application group?

    How to use link generated by application group?

    Hello Vishal,
    You provide the link eg. in a list and candidates just have to click on that if they want to apply.
    Regards
    Nicole

  • How to use single column in a group by clause

    hi frs
    i hve used sum function in a sql how to use a single column in a query.
    for ex
    select sum(sal),ename,job,deptno,empno from emp
    group by deptnowhether its possible to use single column in a group by class.
    i want like this because in my custom report i need it. Report query has more than 30 column so its not possible to use 30 columns in a group by.
    pls help.
    Thanks
    Rajesh

    Maybe something like this -
    Select ename, job, deptno, empno, sal, col1, col2, col3, col4 ......, coln
    From
    Select SUM(sal) sal, deptno deptno_i
    From Emp
    Group By deptno
    ,Emp
    Where deptno = deptno_i
    Shailender Mehta

  • How to use URL class instead of Socket

    Hi all. I am developing a small inventory control system for a warehouse.
    I am suing a Java desktop application that connects to a servlet via Internet.
    I have been searching the net how to use JSSE for my application since i am new to secure sockets and JSSE.
    Since I havent implemented security In my current system yet, i am using URLConnection conn = url.openConnection(); to connect to a servlet.
    However, in a good tutorial that I found about JSSE, sockets are used directly for connection, insted of URLCOnnection. They use the code like this: SSLSocketFactory sf = sslContext.getSocketFactory();
    SSLSocket socket = (SSLSocket)sf.createSocket( host, port ); Since, using sockets is overly complex for me, I want to make use of the URLConnection class instead to keep it simple.
    Could anyone please tell me how to make use of the URLConnection class to establish secure http connection.
    by the way, the tutorial is here:
    http://www.panix.com/~mito/articles/articles/jsse/j-jsse-ltr.pdf
    thanks.

    Here you go. The following code snippet allows you post data to http URL. If you have to do the same to https URL , please let me know.
    OutputStream writeOut = null;
    HttpURLConnection appConnection = null;
    URL appUrlOpen = null;
    //data to be posted.
    String data = "This is the test message to post";
    byte[] bytesData = this.data.getBytes();
    appUrlOpen = new URL(""Your Servlet URL");
    appConnection = (HttpURLConnection) appUrlOpen.openConnection();
    appConnection.setDoOutput(true);
    appConnection.setDoInput(true);
    appConnection.setUseCaches(false);
    appConnection.setInstanceFollowRedirects(false);
    appConnection.setRequestMethod("post");
    appConnection.setRequestProperty("Content-Type","application/text");
    appConnection.setRequestProperty("Content-length", String.valueOf(bytesData.length));
    writeOut=appConnection.getOutputStream();
    writeOut.write(bytesData);
    writeOut.flush();
    writeOut.close();
    String inputLine;
    StringBuffer sb = new StringBuffer();
    reader = new BufferedReader(new InputStreamReader(appConnection.getInputStream()));
    char chars[] = new char[1024];
    int len = 0;
    //Write chunks of characters to the StringBuffer
    while ((len = reader.read(chars, 0, chars.length)) >= 0)
    sb.append(chars, 0, len);
    System.out.println("Response " + sb.toString());
    reader.close();
    sb=null;
    chars = null;
    responseBytes = null;
    ******************************************************************************************

  • How to use Spring MVC instead of assembler.jsp in endeca 3.1.0

    Hi ,
    I am new to Endeca . I want to use spring MVC instead of assembler.jsp .Some body please help
    me how can i do it. Wht all i have to do to achieve it.
    Thanks
    Mark

    Hi Mark,
    When using the 3.1 Assembler in your application, you can use either the jar file directly or set up the Assembler as an HTTP service and process the XML or JSON responses. Neither of these approaches conflicts with using Spring in your application.
    Sean

  • How to Use Partitioning in Mappings

    Hello All.
    Please could you you help me on this one.
    I am using OWB9.2, and would like to use partitioning in one of the mappings.
    It is a simple mapping which maps from one table into another going through transformations and aggregations on the way
    I would like to use the partitioning capabilities of owb so that it uses the partitioned table which is acting as the source.
    I have checked all the options in the configuration for the mapping, but which option should I use!
    Please Help!
    Thanks again.
    Kind Regards
    Saif
    from a very wonderfully wet Sydney, OZ
    (We need the Rain!)

    OWB currently supports hash and range partitions. Use hash partitions if you want the database to partition your data automatically (by generating and managing hash keys based on the partition key column you define). Use range partition if you want to control how data is partitioned in the table (partitions will be created that contain a range of values in the partition key column, for example if the partition key is date_created, you can decide that partition 1 contains records where date created is between january 1 and march 31, p2 dates between april 1 and june 30 etc.).
    The partition parameters can be found in the configuration pannel of the object - right-click on the object and select configuration. There you will find the partition keys, hash partitions and range partitions entries. Click on the white space to create partitions (this is kind of unintuitive...).
    For more details, take a look at the users guide, chapter 5 - Configuring Objects (http://download-west.oracle.com/docs/html/B10996_01/05config.htm#1124708).
    Regards:
    Igor

  • How to use an instance instead of the class itself

    I am building a program but have a problem.
    My program uses a controller class which instantiates a World-class. In the world class has a Vector I make a Vector in which I place all the elements in the world. (I also made an Element class from which all the objects that I put into this Vector extend.)
    Everything except for some methods in the controller class are declared public. I might need to use static, but I do not know how.
    // CONSTRUCTOR CONTROLLER CLASS
    world = new World ();  // instantiate one and only one world
    world.newElement (new Beamer ("beamer", 20. , 20.));  // use a selfwritten method to add a "Star Trek"-like
                              // beamer to the world. I give it a name and position.
    world.newElement (new Avatar ("avt", "beamer"));  // add an avatar which is "beamed up". so what I do is that I use the beamer for the beginposition of the avatar. However, and this is my problem, in the constructor of Avatar (see below) i need the beamer in world, but my compiler cant find world. I probably need to import my World or controller class, but even then: I do not understand how to use an instance (world is an instance. I cant use the World-class as the class does not contain the beamer element)
    public class Avatar extends Element {
         public Avatar (String n, String beamer){
              name = n;
              posx = world.named("beamer").getPosx; // the selfwritten method named finds the
                // element in the Vector that goes with the name. Any ideas to make this code better are welcome too.
              posy = world.named("beamer").getPosy;
    } Any ideas on how to solve this (common) problem in good coding are most welcome.

    I think you are best off if you use static methods and static fields only in your World class. That way you don't have to instantiate it and everyone has access to its methods. This would be then completely analogous to how you access methods and fields of the well-known class System (e.g. when you use System.out.println). This also has the advantage that you are guaranteed to have only one copy of the World.
    Here is an example of how your World class, Avatar class and main code would look like.
    Main code: (note the use of capital W in the name World, referring to class rather than instance).
    // no need to instantiate World, as we call its static methods only
    World.newElement (new Beamer ("beamer", 20. , 20.));
    World.newElement (new Avatar ("avt", "beamer"));  // add an avatar which is "beamed up". World class: (note the static keyword in front of the vector and the methods)
    public class World {
      private static Vector v;       // static field, only one copy of it ever exists
      public static void newElement(Element e)   // static method, can call without instantiating world
         v.addElement(e);
      public static Element named(String n)  // use to look up elements
         ... some code which goes through v and finds element named "n" ...
         ... return reference to that element ...
    }and finally the Avatar: (again note the use of reference to World as a class rather than instance)
    public class Avatar extends Element {
         public Avatar (String n, String beamer){
              name = n;
              posx = World.named("beamer").getPosx;
              posy = World.named("beamer").getPosy;
    } The above example is how I would implement it when you don't actually need instances of the World class.

  • How to use an image instead of Browse Button in messageFileUpload item

    Hi,
    I have sessageFileUpload item in my OA Page to upload files. How can I show my custom image instead of a Browse button that is placed by default. I don't want to show the browse button instead want to use my custom image.
    Thanks

    This is a framework object, you can't change that.
    --Shiv                                                                                                                                                                                                   

  • How to use API to trigger JAM group invitation in ABAP coding?

    Hi,
    We want to trigger a JAM group invitation URL to be sent out in ABAP coding to enable a auto. process at backend. Currently I only know the manual way: clicking invite button in jam group and input user name to find target user and then click send button to send out invitation email.
    But question is how to do in ABAP coding to call any API to realize the same action?
    Many thanks and Best regards,
    Long

    As an ABAP developer you can make use of the SAIL Library to integrate with SAP Jam. With SAIL integrating with SAP Jam is as easy as calling a ABAP OO method. SAIL takes care of the communication with SAP Jam and handles user authentication for you.
    The lower part of http://scn.sap.com/docs/DOC-55050 contains information for ABAP developers like the SAIL developer guide and the SAIL config guide.

  • How to use JNDI datasource instead of database connection settings JDev 10g

    Hi,
    In order to use the different database from other environments, we are not able to use the JNDI datasource configuration settings, all the time need to configure the database connection settings from JDeveloper by changing the database connectivity settings in the JDeveloper for each environment separately, need a solution on how to make the database connectivity unique using the JNDI datasource name for all the environments for database connectivity settings through the application server console rather than changing the database adapter configuration in JDeveloper.
    Please provide the update at the earliest. Your help is greatly appreciated. Thanks in advance..

    What are you not clear on?
    What you need to do is get your developers to conform to a database naming standard, as stated above, so if you have an oracle database that is for eBusiness Suite you get all developers to create a DB connection in JDev called, ora_esb as an example.
    When the developer creates a DB adapter this will create a JNDI name of eis/DB/ora_ebs. When the BPEL project is deployed it looks for the JNDI name in the oc4j-ra.xml file to see its connection details. If they don't exist then they use the developers connection details. The issue with this is that they generally always point to the development DB. It is best practice for the developers to remove the mcf settings in the DB adapter WSDL. This way if the JNDI name has not been configured it will fail.
    So when you migrate from dev-test-prod what you have is the JNDI name eis/DB/ora_ebs. The dev points to the dev instance of ebs, test points to the test instance and so on. This means that you don't need to adjust any code in the BPEL projects.
    cheers
    James

  • How to use standard browser instead of opera in 51...

    Hi,
     In my nokia 5130 mobile. it has opera mini application as a defaut browser.
    But  I want to use the standard nokia default browser.
    if i press 0 key then it opens the standart nokia provided browser and displaying the home page.
    but there i cant find any option to enter the URL and browse any other web pages.
    please help me out,

    Ok,, as you told.. after press 0 then home page gets load.
    but in the options  list there is no such option to give the URL and browse a webpage.
    There is one option called "Browse Web". if i select that, then it opens the opera mini browser.
    is there is any otherway to give the url and browse from standard nokia providede browser instead of opera mini.

  • IMac audio - how to use internal speakers instead of digital out

    Hi. i have my audio system connected to my imac with a toslink cable which works great.
    however in certain cases such as in the evening i do not need to use my surround sound system.
    how can i use just the internal speakers without physically disconnecting the cable at the back???

    I don't think there is a way to do that, unfortunately. However, I don't use the optical output capability (just analog), so it may be different.
    If System Preferences Sound pane Output tab does not have the option to switch to the built-in speakers, also try running Audio Midi Setup in Applications/Utilities/. That utility provides more control options for audio than System Preferences. But, I have a feeling you will not be able switch to internal speakers if anything is connected to the audio output port.
    One thing you can do is get a USB sound device, like the iMic from Griffin Tech.
    http://www.griffintechnology.com/products/imic
    Connect some small powered external speakers to the iMic's output. Because it is a USB audio device, it should appear separately in System Preferences Sound pane Output tab. Then you can switch the output between the digital optical and USB device without disconnecting anything.

  • ASA9.1 how to use route-lookup instead of "NAT-lookup" for egress interface on non-identity NAT

    Hi,
    I have an ASA firewall with three interfaces, inside, outside and Link.
    I have a situation where I need the ASA to perform the following nat rules:
    from "Inside" to "Link" - any source to destination 192.168.51.0/24 - translate source to 10.0.0.19
    from "inside" to "outside" - any source to any destination - translate source to "interface" (internet navigation)
    from "inside" to "outside" any source to 192.168.51.0/24 - translete source to 10.0.0.17
    This is what I am trying to get working:
    nat (any,TEF) source dynamic any 130.130.0.19_nat destination static obj_192.168.51.0 obj_192.168.51.0
    nat (any,outside) source dynamic any 130.130.0.17_nat destination static obj_192.168.51.0 obj_192.168.51.0
    The problem is that the "outside" route to 192.168.51.0 is an alternative route over a VPN tunnel. I'm using sla monitor, so when the "Link" interface is out, the route table changes the network 192.168.51.0/24 to be reachable over the outside interface. but ASA is using the NAT rule to perform "egress interface lookup" instead of route-lookup.
    I know about the command route-lookup on the NAT configuration, but I need to translate the source address and when I try to use the route-lookup command I get an error message:
    ERROR: Option route-lookup is only allowed for static identity case
    Anybody has some suggestion?
    Thanks

    Hi Julio,
    Thank you for the reply.
    It didn't work either.
    Here are the options I get when I use the specific interfaces (using "source dynamic"):
    configure mode commands/options:
      description  Specify NAT rule description
      inactive     Disable a NAT rule
      net-to-net   Net to net mapping of IPv4 to IPv6
      service      NAT service parameters
    If I try to use source static:
     nat (inside,TEF) source static inside_nat 130.130.0.19_nat destination static obj_192.168.51.0 obj_192.168.51.0 route-lookup
    ERROR: Option route-lookup is only allowed for static identity case

  • How to use Dreamweave​r instead of Site Builder

    I created a website using Dreamweaver and used its FTP capability to upload the files.  I used the settings (HOST NAME: ftpmysite.verizon.net, User Name: your user ID (e.g. - jsmith), PASSWORD: your password) that were published here.. http://www.verizon.net/central/vzc.portal?_nfpb=tr​ue&action=FAQ&_pageLabel=pws_content#wlp_pws_conte​...
    Dreamweaver uploaded the files and the Web Space Monitor lists all of the files but they are not accessible using my personal URL (http://mysite.verizon.net/username).  In the Disk Space tool in Site Builder shows the files under a category of "Other Files (including system files)."
    How can I get my website to be active through my personal URL without using Site Builder?
    Thanks for your help!
    Solved!
    Go to Solution.

    somegirl wrote:
    Is the main page file listed as index.htm or index.html?
    When web designing, it doesn't matter if it's either .htm or .html. Just as long as every other page that you DO link the index file to that it's consistent.
    For example, I cannot have on another page:
    <a href="index.htm">Text here</a>
    When the original index file is a .html
    So long as you're consistent when linking each file to the original index it should be fine. The Suffix that it has really hasn't mattered for years.
    If you use 'pls' because it's shorter than 'please' I'm going to say 'no' because it's shorter than 'yes.'
    Wanna see my YouTube Channel? Message me about it really quick!

  • How to use simple SQL instead of Connect By Prior

    Currently, I am using "connect by prior" query in the application, but for reason I don�t want to use this connect by query so can any one please tell how does I get the same result by using SQL, I tried this by using procedure but unable to get the same result, specially LEVEL of the tree.
    So please tell, how would I get the correct data.
    Thanks in advance,
    AMIT.

    Hi,
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted) I don't believe the unformated code you posted is what you're really running, since it has a syntax error ("... WHERE START WITH ..."). Please post code that really works with the sample data you posrted.
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, scott.emp, which contains a hierarchy), then you can omit (2).
    Formatted tabular output is okay for (3). Type these 6 characters
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after the tabular text, to preserve spacing.
    As Alex said, why don't you want to use CONNECT BY?
    Are you getting the correct results now, but just looking for a different way of getting them?
    Depending on your exact requirements, you could write a PLSQL function that mimics LEVEL. Don't expect it to be fast.
    Nested Sets is a completely different way of modeling trees.
    Some things are much easier with Nested Sets than they are using the Adjacency Model (the parent-child model that uses CONNECT BY).
    But some things are much harder with Nested Sets, and LEVEL is one of them.

Maybe you are looking for

  • How to get photos from mac to iPhone 6? when i try it just comes up iCloud instead of my photos

    how to get photos from mac to iPhone 6? when i try it just comes up iCloud instead of my photos

  • Shockwave flash constant crashing

    Since updating from firefox 26, I have experienced constant shockwave flash hangs in both Firefox and Chrome. I have done numerous rollbacks, uninstalls, clean reinstalls, and driver updates. Anything that fixes the issue only fixes it for a few hour

  • HTML5 Video overlaps scroll bar & Addon-Bar

    Example Page: [http://html5demos.com/video] Resize the window to cause the bottom half of the video to be off-screen (just drag the corner of the window). The video area will overlap the horizontal scroll bar (and also the Add-on Bar if displayed). S

  • Pay scale increase

    HI, I have a requirement in Payroll International where there is a fixed table of increament slabs as given below Grade     Min Basic   Median   Max Basic   Increment factor i have grouped Grades as payscale levels . Now in Standard tables , i guess

  • Can not do the slide to unlock

    My Iphone IOS 3.0.1 cannot be done the slide to unlock.