Count on table

have this table OCC
COD.............NAME
001.............TOM
001.............SAM
002.............CAT
003.............DOG
003.............SAM
003.............TOM
004.............JACK
005.............TOM
005.............SAM
I'd like to get just cod with more name:
I tried this
SELECT COUNT(NAME) TOT, COD
FROM OCC
GROUP BY COD
HAVING COUNT(NAME) > 1
OK, I get this:
TOT..........COD
2............001
3............003
2............005
but I'd like to get also the records.
For example I want this (only the records with more name):
COD.............NAME
001.............TOM
001.............SAM
003.............DOG
003.............SAM
003.............TOM
005.............TOM
005.............SAM
How can I write this query??
Thanks

And you can squeeze a bit more performance out of the database by using analytic functions if you have at least an 8i database. This pushes the counting down to the level of the initial query, and prevents you from having to then run a 2nd, outer query.
<pre>
SELECT cod,
NAME
FROM (SELECT cod,
NAME,
COUNT (*) OVER (PARTITION BY cod) AS cnt
FROM occ)
WHERE cnt > 1;
</pre>
Scott

Similar Messages

  • Select count(*) from table in oracle 11g with direct path read takes time

    select count(*) from table takes long time, even more than couple of hours..
    direct path read is the wait event which is almost is at 99%..
    can u someone provide some info on this.. on solution.. thankx

    knowledgespring wrote:
    table has millions of records... 130 millions..
    select count(*) from BIG_SIZE_TABLE; --- executed in sql plus command prompt.
    Rows     Execution Plan
    0  SELECT STATEMENT   MODE: ALL_ROWS
    0   SORT (AGGREGATE)
    0    TABLE ACCESS   MODE: ANALYZED (FULL) OF 'BIG_SIZE_TABLE' (TABLE)
    Elapsed times include waiting on following events:
    Event waited on                             Times   Max. Wait  Total Waited
    ----------------------------------------   Waited  ----------  ------------
    SQL*Net message to client                       1        0.00          0.00
    enq: KO - fast object checkpoint                1        0.01          0.01
    Disk file operations I/O                       18        0.00          0.00
    direct path read                            58921        0.34        418.54direct path read time waited is : 58921 total time waited: 418.54
    That 418 seconds - not the hours you reported earlier. Is it possible that your connection to the database broke ?
    On a typical system, by the way, you can usually turn one direct read for tablescan into 1MB, so your scan seems to have covered about 59 GB, which seems to be in the right sort of ballpark for 130M rows.
    we have another query and when we test the query execution using v$sql, is_bind_sensitive =N, how to make is_bind_sensitive=Y all the time.. There is a hint /*+ bind_aware */ - I'd have to check whether or not it's documented at present. It might help.
    I would be interested in hearing why you think the hint should be bind sensitive when the optimizer doesn't.
    Regards
    Jonathan Lewis

  • How to find the count of tables going for fts(full table scan in oracle 10g

    HI
    how to find the count of tables going for fts(full table scan) in oracle 10g
    regards

    Hi,
    Why do you want to 'find' those tables?
    Do you want to 'avoid FTS' on those tables?
    You provide little information here. (Perhaps you just migrated from 9i and having problems with certain queries now?)
    FTS is sometimes the fastest way to retrieve data, and sometimes an index scan is.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
    There's no 'FTS view' available, if you want to know what happens on your DB you need, like Anand already said, to trace sessions that 'worry you'.

  • Row/column counter for tables

    Hello,
    I know this is very basic, but so far examples I dug up don't really anything remotely to what I want.
    I have 3 databases. Well they are defined as "connections" in SQLDeveloper I hope that's the same I am still not used to Oracle abstractions.
    Each has several tables. All I want is loop through each of the 3 DBs and log row count and table count.
    Say DB1:
    Rows: Columns:
    Table1: x y
    Table2: x y
    I don't really care what's inside them. I found one example that did it but it listed some system tables that aren't part of my db. Changing "owner" didn't really help.
    From the value of the variable "Owner" means a database, is that correct?
    Oh and I also don't care if the code is "inefficient", tables aren't that big.
    Thanks in advance.
    Edited by: 940349 on Jun 14, 2012 6:22 AM

    not sure what you are planning to achieve, but you can use below query to get owner of table, table name , column name, number of tables by owner and number of column in a table (belonging to owner). This will require access to dba_tab_columns.
    select owner,table_name,count(*) over(partition by owner) count_table,column_name,count(*) over(partition by owner,table_name) count_column from dba_tab_columns;

  • How do I execute "Select count(*) from table " in OCI

    Hi,
    I am new to OCI and so this question may seem stupid. I would like to know how to execute the query "select count(*) from <table>" using OCI V8 functionality? Also after how do I get the result into a integer datatype? I have gone through most of the demo programs but is is of little help to me.
    Thanks in advance...
    Regards,
    Shubhayan.

    Hi,
    Here is sample code to give you some idea how to do it. If you want some more info let me know.
    Pankaj
    ub4 count;
    // Prepare the statement.
    char szQry = "SELECT count() FROM T1";
    if(OCI_ERROR == OCIStmtPrepare(pStmthp, pErrhp, (unsigned char*)szQry, strlen(szQry), OCI_NTV_SYNTAX , OCI_DEFAULT) )
         cout << "Error in OCIStmtPrepare" << endl;
         exit(1);
    // Bind the output parameter.
    OCIDefine *pDefnpp;
    if(OCI_ERROR == OCIDefineByPos ( pStmthp, &pDefnpp, pErrhp, 1,
    &count, sizeof(ub4), SQLT_INT,
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
                        OCI_DEFAULT) )
         cout << "Error in OCIDefineByPos" << endl;
         exit(1);
    if(OCI_ERROR == OCIStmtExecute(pSvchp, pStmthp, pErrhp, 1, 0, NULL, NULL, OCI_DEFAULT) )
         cout << "Error in OCIStmtExecute" << endl;
         exit(1);

  • Is it possible to add counter in table maintenance (automatically)?

    sap ver. 4.7
    is it possible to generate counter in table maintenance (automatically)?
    i mean without building dialog screen  / table control  .
    exmple  :
    the user insert .....
    name
    name
    name
    name
    i add as key (automatically)
    1
    2
    3
    4

    Hi,
    It is possible to do the same by not adding new dialog screen / table control .All table maintainance are infact module pool programs ...While creating a tabe maintainance we have an option of 2 step or 1 step ->these screen numbers are the ones which are displayed  in table maintainace SM30
    So we can infact do coding in PAI and PBO of these screens.
    But the main disadvantage is that if you re-generate the table maintainace the code in PAI and PBO gets deleted for that screen
    eg:if you table maintainance is assigned to function group ZFXNGROUP -> go to se38 -> see program SAPLZFXNGROUP
    just add SAPL to function group suffix to get the module pool and the view screen number(same as that given in table maintainace for step1 and step2) ..in the PBO /PAI write the necessary code to increment the counter..
    we can just do a loop at screen and hide the counter field while incrementing in the PAi/PBO logic as required
    But once again,regeneration of table maintainace in the screen overwrites the PBO/PAI..the best we can do is create subroutines and write the code in a new include..so that everytime the code is overwritten...we need to just write the subroutine name in flow logic since includes are not overwritten in regenerations
    Also if we use the same function group for multiple table maintainance we have different screens,Pls make sure you are not editting the wrong screens......
    Hope it helps
    Pls check and revert
    Regards
    Byju

  • How about get item count of table in formGroup.vm

    JHeadstart Team:
    I want change maxColumns=" 1" or" 2" by item count of table .but I do not know how about get item count of table .
    #if (${JHS.current.group.columns} > 10)
    #set ($majin = 2)
    #else
    #set ($majin = 1)
    #end
    <af:panelForm rows="1" maxColumns="$majin" width="${JHS.current.group.formWidth}" id="${JHS.current.group.shortName}FormItems">
    majin
    #FORM_ITEMS()
    </af:panelForm>

    You can do this using the following syntax:
    #if (${JHS.current.itemContainer.items.size()}>10)
    maxColumns="2"
    #else
    maxColumns="1"
    #end
    Steven Davelaar,
    Jheadstart Team

  • Row count for tables from 2 different databases

    Hi,
    i wrote a query to get counts from all the tables in one schema to another schema. this generates the select count (*) from tables and gives me the counts, but i want to get the counts such as
    table1 -- 100 -- DB1
    table1 - 110
    table2 - 230 - DB2
    table2 - 230 etc...
    here is my query that works but display of the output is the way i wanted. can someone help me getting the output as above described.
    select 'select ''PTO'', count(*) as '||(table_name)||'_count'||' from '||table_name||';'from dba_tables
    where owner = 'TEST'
    union all
    select 'select ''PFO'', count(*) as '||(table_name)||'_count'||' from '||table_name||';'from [email protected]
    where owner = 'TEST';
    thanks...

    DUPLICATE post
    count of rows in a schema tables

  • Unique row count in table footer

    JDev 11.1.1.6
    Hi,
    In my current table, I am able to show total row count at a table footer by using #{bindings.<myVO>Iterator.estimatedRowCount}.
    I have a request from my user to show unique total row count. For example rows below:
    1 A
    2 B
    3 A
    4 C
    The footer should show:
    4 3
    The second column has A, B, and C where A is counted only 1 (unique). Is there a way to achieve this?
    Thanks.

    Hi RRA,
    This may work for a static # of rows (no filtering). In the table I use, I can do filtering and that certainly will make the count result be different if I use another VO for distinct result.
    Thanks.

  • Can we get the count of table in dump(.dmp) file

    Hi,
    I have a export backup (exp)of all the users of database in one dumpfile(.dmp).
    I want to import only one table(T) in specific schema is it possible right.
    And i want to know how many records (count(*)) in that dump file table(T)
    Reason: Some body deleted the table accedentally...
    version: 10.2.0.4
    Thanks,
    Srinivas
    Edited by: Srini on Apr 17, 2012 3:01 AM

    Srini wrote:
    Hi,
    I have a export backup of all the users of database in one dumpfile(.dmp).
    I want to import only one table(T) in specific schema is it possible right.That is possible
    >
    And i want to know how many records (count(*)) in that dump file table(T)
    Reason: Some body deleted the table accedentally...
    version: 10.2.0.4
    If you have the logfile that comes with the dump, you can easily lookup the number of rows.
    Success,
    FJFranken

  • Count of tables and its rows...

    Hi all,
    I have a table ( back_up) which contains tablename,owner,last update..etc..when i count this shows 36 tables.
    now issued one query:
    select table_name,num_rows from all_tables where table_name in( select table_name from back_up);
    when i run the query it displays only 28 tables.
    Now i want to findout which are the tables are displayed i.e that is not matched)..
    any suggestions..
    Thanks
    asp

    hi,
    SELECT * FROM back_up WHERE table_name NOT IN (
    select table_name from all_tables where table_name in( select table_name from back_up)
    Also U can use Mines as;
    SELECT table_name FROM back_up
    MINUS
    SELECT table_name FROM all_tables
    i guess u need this???
    BR...
    efe
    Message was edited by:
    Promethe

  • Counting grouped table rows

    Hello experts.
    I trying to build a model which will do the following thing:
    Calling a data service (a BAPI for that matter), then grouping the data recieved, presenting it in a table and a form next to it (It can be in the table itself) showing how many rows i have for each group.
    It has to be dynamically, is there a way to do it?
    thank you.

    >
    Govindu Nagotla wrote:
    > Hi,
    >
    > on which SP you are Working,
    >
    > This can be done by Grouping operator.
    >
    > Drag a Group operator from Compose Panel and Add the group operator to the output port of ur data service.
    >
    > Then Configure the group operator in the way you want.
    >
    > If did not get you get back to me.
    >
    > Regards,
    > Govindu
    Hi Govindu.
    Sorry, I forgot to mention it, I'm working on SP14.
    and I still cant understand how the Group operator can help me. I want to count the rows of every subgroup of a group. (For example: the group is cites - How many rows for NY, How many for LA and so on).
    Motty.

  • Counting fact table records within brackets

    Hi,
    I have a star schema setup in OBIEE, consisting of a fact table of transaction records, linked to a customer dimension and a time dimension via PK-FK relations.
    One of the requirements is to count the number of customers based on how many transactions they have done per time period. I imagine solving this by creating logical colums such as "# customers (1-10 transactions)", "# customers (11-20 transactions)", etc. The counting should be based on the current level of drill-down in the time dimension.
    Any advice on how to approach this would be greatly appreciated
    best regards
    M

    Thanks for you reply, it brought me a lot closer to a solution. So far i've been able to create a bracket attribute on the customer dimension (via Answers and then into Administrator, as advised). I've verified this against the database, and it categorizes each customer correctly.
    The remaining challenge is that I want to see the count within each category on an aggregate bracket level rather than per customer. Using one attribute ("customer bracket") which can take on one of several values (e.g. "0", "1-10", "11-20", etc.) i'm not sure how to accomplish this.
    As a workaround i tried creating one column in Answers for each bracket, taking on the value 1 for records falling within that bin, and 0 for all other records. Treating the column as numeric, and adding a sub total (sum), i get the answers i want for each bin. The problem here however, is that one line (value 0 or 1) is shown for each customer record, which makes the report useless for most practical intents and purposes as thousands of records are shown.
    Any thoughts on which method i should go ahead with, and how?
    regards
    M

  • Need count of tables

    Hi Friend ..
    we are connecting through a db link to another prod database which is 10g and running golden gate to extract some data . I need to take the count of a few tables which are either update or inserts from their main schema in a day .
    Can you please help me how to get the count of updates/inserts on a table in  a day without affecting the performance of that database .
    Regards,
    DBApps

    985871 wrote:
    Hi Friend ..
    we are connecting through a db link to another prod database which is 10g and running golden gate to extract some data . I need to take the count of a few tables which are either update or inserts from their main schema in a day .
    Can you please help me how to get the count of updates/inserts on a table in  a day without affecting the performance of that database .
    Regards,
    DBApps
    If you would check the "reports' of the golden gate, they would also provide you this count. Other than that, Auditing comes to mind.
    Aman....

  • Select  and count from table

    Hi,
    I have table with  project end pernr and i wont to count how much
    employee  i have for  projects
    e.g.
    pernr        project
    123         e0-111
    565         e0-111
    158         e0-111
    145         e1-222
    456         e1-222
    665         e1-222
    222         e1-222
    222         e6-777
    i wont to get:
       e0-111 3
      e1-222  4
      e6-777  1
    What is the best way to do that ?
    Regards

    Keep you internal table like this way
    data : begin of itab occurs 0.
    data : project like zmytable-project.
    data : cnt   type i.
    data : end of itab.
    Select project count(*) as cnt
    from zmytable
    into table itab
    group by project.

  • Physical Inventory Count Document TABLE

    Hi ,
    Can anyone please tell me the TABLE for physical Inventory Count .
    In which TABLE , all the datas such as physical document number etc will be saved .
    Regards,

    Hello Sandeep,
    You will find count entry in
    - ISEG if using IM.
    - LINV if using WM.
    Thanks & regards,
    Arif Mansuri
    Reward the point if answer is useful.

Maybe you are looking for