How to assign the ID of group for each group in the SQL query.

Hi all

I want to assign the ID of group for each group (group ID of series). I tried with the row_number function but did not work for my requiredment. Here is my sample data and my requirement.

Col1
A
A
A
A
A
B
C
D
D
D
D
E
E
E
F
G
G
G

I want to get number of each column with ID group assign to it value. Here is my example output

Col1 County Group ID
A 5 1
A 5 1
A 5 1
A 5 1
A 5 1
B 1 2
C 1 3
D 4 4
D 4 4
D 4 4
D 4 4
E 3 5
E 3 5
E 3 5
F 1 6
G 3 7
G 3 7
G 3 7

Select col1, count (1) NTC (col1 partition).

ROW_NUMBER() over (partition by col1 by col1 order) tbl_test grp_id.

Please help me solve this problem.

SELECT

COL1,

COUNT (*) ON MYCOUNT (COL1 PARTITION).

DENSE_RANK () OVER (ORDER BY COL1) GROUPID

Of

T1;

Tags: Database

Similar Questions

  • How to get the sql query result?

    Hello

    Currently I use LV2012 to connect to an Oracle database server. After the Oracle Express and Oracle ODBC driver facilities/settings made.

    I managed to use the SQL command to query the data through my command prompt window.

    Now the problem is, how to do the same task in Labview using database connectivity tools?

    I have build a VI to query as being attached, but I have no idea of what range to use to get the result of the query.

    Please help me ~ ~

    Here is a piece of code that I use to test the SQL commands, you can use the part that retrieves the results of sql.

    It is also possible to get the rear column headers, but it's for the next lesson!

    ;-)

  • How to find the sql query generated by BI Publisher

    I'm looking for the physical sql query generated by BEEP when I send parameters as part of the data model.

    Of course, this can be noted in newspapers...

    Can anyone tell me the location of newspapers?

    Thanks in advance

    Have a look here http://gerardnico.com/wiki/dat/bip/log
    I explain a bit how you can get the newspaper.

    See you soon
    Nico

  • How to get the SQL query running of af: search?

    I use JDeveloper 11.1.2.3.0. I have a page where I've set up an af:query and an array of result. The problem is that I can't get the exact query that is used during the execution of this component in a managed bean method. Is it possible to get the query string that is run within the af: query?

    Thank you

    Hello

    Method of the ViewObject getQuery() returns what you need;

    You can replace the executeQueryForCollection(), and prior to calling super, you can print the result of getQuery() method:

    public void executeQueryForCollection (rowset Object,

    Object [] params,

    {int noUserParams)

    System.out.println ("SQL =" + getQuery());

    call the super method here...

    }

  • How to find the sql query

    four months back someone updated my table of billing through sql developer.

    How can I find the details of the request or the original data.

    now the problem is that we rebooted the server, if it's not rest with time stamp.

    log mode is Archieve record only.
    Please help me

    I don't know why you're getting this error, I tried and it works:

    SQL> exec dbms_logmnr.add_logfile( logfilename=> 'C:\oracle\product\11.2.0\dbhome_1\RDBMS\ARC0000000736_0765299251.0001', options=> dbms_logmnr.new);
    
    PL/SQL procedure successfully completed.
    
    SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_logmnr.start_logmnr
    
    PL/SQL procedure successfully completed.
    
    SQL> select seg_owner,seg_name,sql_redo,sql_undo from v$logmnr_contents;
    
    .....
    
    35 rows selected.
    
    SQL> exec dbms_logmnr.end_logmnr
    
    PL/SQL procedure successfully completed.
    

    @Boris - you don't have to have an additional connection to the database. The thing is that if you don't have additional logging, Oracle will give you only the ROWID of the records and if it is not the same database or something has changed (as "alter table... move"), ROWID is not relevant. If you enable additional logging, you will get more information on the line (like the other columns or PK) which will help you a lot to identify RELEVANT changes. As I said, it is not mandatory, but as you say, if you want extra logging, it must be turned on BEFORE the changes in the database.

    Hope that's clear,
    Liron

  • How to get the sql query

    Hello

    I already set date value as below.
    SET THE VALUE OF START_TIME = 2011-08-12 09:00
    DEFINE END_TIME = 2011-08-12 10:00
    and executes the table based on the defined date as below,
    Select * from my_table
    where
    (to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS))
    GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS)
    GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS)
    GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS));
    ) but now I want to query the table based on the time,

    Any help please,.

    Hello

    It is not very hard in SQL * more.

    First of all, put your query in a script file, like this one, called hour_query.sql:

    --     hour_query.sql          Show data from my_table for a given time period
    
    PROMPT     The data below shows the period from &1 to &2
    PROMPT
    
    SELECT     *
    FROM     my_table
    WHERE     accounting_start_time     <= '&2'
    AND     '&1'               <= accounting_stop_time
    ;
    

    Parameters & 1 and & 2 are beginning and end of time, for example "2011-08-12 09:00".
    Note that this does not use TO_DATE. If you have incorrect strings in columns that must be DATEs, no errors occur.

    Assuming that hour_query.sql is located on p:\some_dir\, you want another script that runs hour_query.sql 24 times, like this one, which I will call all_hours.sql:

    @p:\some_dir\hour_query  "2011-08-12 09:00:00"  "2011-08-12 10:00:00"
    @p:\some_dir\hour_query  "2011-08-12 10:00:00"  "2011-08-12 11:00:00"
    @p:\some_dir\hour_query  "2011-08-12 11:00:00"  "2011-08-12 12:00:00"
    ...
    

    (I just did 3 hours to test. You can easily make that 24 hours).

    The following code creates and then runs all_hours.sql:

    -- Turn off SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SET     VERIFY          OFF
    
    -- Write all_hours.sql
    SPOOL     p:\&some_dir\all_hours.sql
    
    WITH     got_start_time     AS
    (
         SELECT TO_DATE ( '2011-08-12 09:00:00'
                            , 'YYYY-MM-DD HH24:MI:SS'
                     ) AS start_time
         FROM    dual
    )
    SELECT     '@p:\some_dir\hour_query  "'
        ||  TO_CHAR ( start_time + ((LEVEL - 1) / 24)
              , 'YYYY-MM-DD HH24:MI:SS'
              )
        ||  '"  "'
        ||  TO_CHAR ( start_time + ( LEVEL      / 24)
              , 'YYYY-MM-DD HH24:MI:SS'
              )
        ||  '"'
    FROM    got_start_time
    CONNECT BY     LEVEL <= 3     -- You can make this 24, or any other number
    ;
    
    SPOOL     OFF
    
    -- Turn on SQL*Plus features turned off earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    -- Except VERIFY.  leave that OFF while all_hours runs
    --SET     VERIFY          OFF
    
    -- Run all_hours.sql
    @p:\some_dir\all_hours.sql
    
    SET     VERIFY     ON
    
  • How to find the sql query by using the hash value

    Hello

    DBVERSION: 9.2.0.8

    I generated the statspack report and I want to see total request and I hash_value here.

    in v$ sql can't see all querys... .pls suggest me other ways...

    Thank you
    Srini...

    Have you seen Peter's response? There is no installation other than that would be to store the history of the IMO. Another reason that you must pass to 10g or 11g better, now.

    Aman...

  • How to assign the next value in the sequence directly in a variable?

    How to assign the next value in the sequence directly in a variable without using a table TWICE in PL/SQL.

    BluShadow wrote:

    How about a quick test on 11g, just to see if you directly select a sequence in a variable is significantly better than the mark of DOUBLE.

    ...

    Nope... no obvious difference.

    This is because there is none: Oracle's SELECT sequence. NEXTVAL FROM DUAL under the covers. The direct assignment is just a convenient encoding for us, but it does not change the work that accomplishes Oracle.

    create sequence s;
    alter system flush shared_pool;
    declare
    l_num number;
    begin
    l_num := s.nextval;
    end;
    /
    select sql_text from v$sql where parsing_schema_name = user;
    
    SQL_TEXT
    Report the number of l_num; begin l_num: = s.nextval; end;
    Select sql_text from v$ sql where parsing_schema_name = user
    Select double S.NEXTVAL
  • How to assign the temporary tablespace to a table

    How to assign the temporary tablespace to a table

    temporary tablespace can be attributed to the user.

  • How to select only the part by using the sql query

    Hello

    I have the task to retrieve only the integral of the input text by using the sql query.

    The entry is as follows

    Entry for the price setting

    $12.5 (FYI without space)

    $ 12.5 (FYI single space)

    $ 12.5 (double space FYI)

    $12.5 (FYI multiple space)

    $12.5 (FYI multiple space)

    Output expected of 12.5

    The price is the type varchar2 column in the store_price table.

    Please let me know how to achieve this.

    Thanks in advance.

    If this is always the case that you get a $ followed by a number of places, you can use something like:

    Select to_number (ltrim ('$ 12.5',' $')) DOUBLE

    or

    SELECT ltrim ('$ 12.5',' $') OF double

    but take care of your nls_numeric_character settings if they are defined so that, for example, a comma is the decimal separator, you will have a problem.

    HTH

  • How can I create sequential shooting (1 for each 'row') numbers in a script in multiple column?

    How can I create sequential shooting (1 for each 'row') numbers in a script in multiple column?

    Sorry, but for now there no such function to put sequential numbers in the column number drawn.

  • How to measure the performance of the sql query?

    Hi Experts,

    How to measure the cost of performance, efficiency and CPU of an sql query?

    What are all the measures available to a sql query?

    How to identify the optimal query writing?

    I use Oracle 9i...

    It'll be useful for me to write the effective query...

    Thanks and greetings

    PSRAM wrote:
    Could you tell me how to activate the PLUSTRACE role?

    First put on when you do a search on PLUSTRACE: http://forums.oracle.com/forums/search.jspa?threadID=&q=plustrace&objID=f75&dateRange=all&numResults=15&rankBy=10001

    Kind regards
    Rob.

  • How to find the sql queries executed in one day with the sql and runtime text

    Hi Experts,

    Please tell me the sql query to find out the queries executed on a particular day and the runtime and the sql text of the query.

    Please reply urgent.

    Thanks in advance

    Database instance 'A' may have run 100 SQL queries today.  As for the instance of database 'B' could have exploited queries SQL 1 million today.  Instance of database 'B' to 'keep' the 1 million SQL statements - in memory or on disk do you expect?  Of course not.  There the age or flush or invalidate memory SQL statements.  He can't keep them on the disk (imagine running a completely different set of 1.2million SQL statements tomorrow and 1.3 the next day).

    AWR and StatsPack can make counts the number of "n" top of the page ("n" default to 30) SQL statements which are still present in the cache of the library (not years, rinsed, invalidated) when a snapshot was taken.  They can't declare "all" SQL statements.

    To return to your needs.  WHY do you need all the SQL statements?  Or are there only certain operations specific SQL would you be interested?  Could they have been treated by allowing audit (for example, UPDATE and DELETE with EXTENDED verification instructions)?

    Hemant K Collette

  • How to import the .sql file in oracle apex?

    I am new to oracle apex...

    How to import the .sql file in oracle apex?

    I have to import a table in apex...

    This script I have to write in the .sql file...

    pls help...

    Published by: 794244 on January 31, 2011 21:31

    Hi Manu

    You can import and browse workshop SQL, SQL Scripts .sql files. If you have multiple SQL statements in your script, make sure that they are separated by the / character

    Andy

  • How to get the SQL if I get exception

    I get this exception and do not know what was the actual sql with the variables of liaison who was executed.



    sqlmesg = error in the select query to retrieve the segment associated with a pair of cables: ORA-01006: there is no bind variable

    y at - it a way to get the real sql executed so I know what mistake I did.

    I thought your question was about how to view the SQL statement and bind variables in the exception. The answer to that is to put variables in the exception message.

    The root cause of the problem seems to be that your dynamic SQL statement may require 3 or4 variable bind but your USING clause specifies always 4 values if the underlying SQL statement has 3 positions, it will lead to an error.

    Justin

  • How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    FROM dbo. [tb1]
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
    )
    DELETE one
    FROM dbo. [tb1] AS an INNER JOIN b cte
    ON a.col1 = b.col1

    Hello
    Something like this maybe:

    DELETE FROM dbo.tb1 a
     WHERE EXISTS (
      SELECT 1
        FROM dbo.tb1 b
      WHERE a.co11 = b.col1
          AND a.col2 = b.col2
       START WITH b.col1 = 12
      CONNECT BY b.col2 = PRIOR b.col1)
    

    Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.

Maybe you are looking for

  • My iMac sleep

    I have an iMac 27 "end 2015 a few weeks ago, and the sleep function worked fine. But all of a sudden yesterday, he refuses to go to sleep. I used to use the shortcut keyboard option + command + eject, but it does not work. The screen just turns off.

  • How can I stop my iPhone and the iPhone and my wife to keep each other recent call logs?

    On my iphone and on my wife's iPhone, you can find each other's recent call history. It's new.  Since the beginning of the iPhone, we have synchronised calendars and contacts, but never synchronized "recent call" logs. How can prevent us this? We are

  • Convert MP3 320Kbs in 192 Kbps files

    I've marked "do not show again"the warning box"convert files to 192 Kbps" that appears when I import songs downloaded from the Google game. How can I check this option?

  • Backup Windows 7 Pro 64-bit question

    Hi all I know there are a lot of posts on this subject, however, I want to use a backup program to back up only the My Documents folder. I store everything in that folder that I'm working on. Programs and other things is in the correct places [progra

  • Error "TI drivers video card are out of date" when you try to play videos on Windows Media Player

    I tried to convert videos using the converter from DVDVideosoft video I received a message that says ATI video card drivers are outdated. I tried to download and install the latest drivers and I got the blue screen of death. When I rebooted the compu