Counting repetitions from a query

Hi,
this is a fairly simple problem I am sure but I can't seem to
get my head round it!
I have downloaded a CSV of my sold items from ebay. I have
managed to query the CSV no problem, the thin is though, I want to
count how many times each item id appears in the file. for instance
I want to know how many times itemid 1 appears and how many times
itemid 2 appears etc.
Is it best to do this in the SQL statement or is there a CF
function that can do this for me?
basically the result I want is something like this:
ItemID (count)
1 (5)
2 (1)
3 (10)
4 (65)
5 (1)
etc etc
Thanks for your help!

SELECT itemID, COUNT(*) AS itemCount
FROM yourtable
GROUP BY itemID
Phil

Similar Messages

  • Returning a count from a query using Union

    Hi. I'm attempting to select a count from this query and then display the total in a message, but I'm getting a 'Too many rows returned' (ORA-01422). Can anyone tell me how I can achieve a total for this query?
             SELECT nvl(count(*),0)
           INTO conflict_cnt
           FROM dropper_assign
           WHERE dropper_id = :dropper_vacations.dropper_id AND
                trunc(sched_date) between :begin_dt and :end_dt
              union                          
       SELECT nvl(count(*),0)
        FROM exfc.bundle a, splits b
        WHERE a.bundle = b.bundle AND
             b.dropper_id = :dropper_vacations.dropper_id AND
             trunc(a.actual_dt) between :begin_dt and :end_dt;
              call_alert.the_error('test: '||to_char(conflict_cnt));Any help would be greatly appreciated.

    Thanks Christian, I can know return to my favourite present occupation named HOLIDAYS ;)
    btw with count function as the first message
    WITH
      data AS
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 10
        UNION
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 20
    SELECT
      SUM(cnt)
    FROM
      data
    SUM(CNT)              
    30        
    /* and */
    WITH
      data AS
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 10
        UNION ALL /****** returns me also 30 *****/
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 20
    SELECT
      SUM(cnt)
    FROM
      data
    SUM(CNT)              
    30       result will defer only if both count return exactly the same value so definitely UNION ALL for that case or the simple solution I have provided before ...
    but leave it. that's enough messages for this thread ;)
    Jean-Yves
    Edited by: JeanYves Bernier on 9 août 2011 17:42

  • Is it possible to count the rows returned from a query?

    Hello,
    When using JDBC is there anyway of finding out the number of
    rows returned from a query before actually getting each row?
    In Forms 4.5 you can use the count_query function, does anyone
    know of an equivalent function or work around in JDBC and/or
    SQLJ?
    Thanks.
    null

    Pasi Hmlinen (guest) wrote:
    : Try
    : SELECT COUNT(*) FROM the_table WHERE <conditions>;
    : Hope this helps,
    : Pasi
    Thanks for the advice, I'm currently using SELECT COUNT(*) but
    I'm looking for a more efficient way of doing it. If I SELECT
    COUNT each time then I have to prepare and execute a SQL
    statement each time. What I want to do it execute a single SQL
    statement to return my results and somehow find out the number
    of rows in the resultset without having to go back to the
    database.
    Gethin.
    null

  • How to count no of records returned from a query?

    Hello,
    I need to find out how many records displayed from a query without writing any other queries.
    i mean that.
    I have a query such as:
    query = "select * from users";
    and the resultset for it is rs.
    and i need to display how many records fetched from this query without using any other query such as "select count(user_id) from users" etc.
    Is there any function ?

    No, unfortunately there is no method or property that will tell you how many rows have been returned by a query.
    People use many different techniques.
    1.The simplest would be, keep incrementing a counter in while ( rs.next() ) and at the end you'll have the count. But only at the end, after the loop.
    2. Run another query with count(*) just to fetch the count.
    3. Run the same query twice, once for counting and then again for printing out. Very dumb idea though, might as well do 2. suggested above.
    4. If you have a scrollable resultset, you could go to the lastRecord and then getRow number and hence know how many there are and then rewind the resultset. I don't know how advisable using scrollable resultsets is.
    5. Create a slightly clumsy query like : select count(*) as "totalcount", emp_id, emp_name, emp_email, emp_phone from employees group by emp_id, emp_name, emp_email, emp_phone. You'll need to use the group by clause since count() is an aggregate function and you can't mix aggregate functions and columns unless you add the group by to all the columns you're fetching.

  • Get the record count from a query

    Hi,
    does anyone know how to get the record count from a sql query?
    e.g: I've got a ResultSet from the Statement.excuteQuery(), and I want to know how many records this ResultSet contains, how to get this?
    I'd read thoughout the documents of Statement and ResultSet, but couldn't find a solution, do I have to use another seperate query such as "select count(*)" to do this?
    thanks.
    Yang Liu

    If you are not using a scrollable result set then the following is the best way to do it.
    there are several key words in SQL that can be used, the one you are interested in is count();
    so if your query at the moment is
    "select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
    "select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
    ResultSet rs = ps.executeQuery();
    int rowCount = rs.getInt(1);I hope this helps :)

  • IR Dashboard report from new query not getting all Quick Filter selections

    I inherited an IR Dashboard .bqy and my user recently added a new Query, Result, Table, and Report section to it. I cannot get the report to dynamically filter based on the date chosen in the existing Quick Filters section. It seems to be filtering the Location properly (drop down in Quick Filters section), but not the date. Her result section refuses to show anything less than ALL dates from the query.
    The other reports/pivots already on the dashboard work fine with all QuickFilters.
    In my attempt to integrate her new report in to the dashboard I add a new hidden "dummy" pivot (based on the existing query btw, not the new query-could that be the issue? it's dummy though so i figured it was ok), reference this pivot in the Embedded Targets object I found by adding "Object~Pivot4|Type~9|Target~Casket Margin Summary" line,
    went to Dashboard Studio and was able to Associate this report in to the right frame, etc.
    In the script behind the QIQ date "Set Filters" button I saw this code for the existing "Result_Detail" section so I added a line for my new "Results_Merch Detail" section.
    var objServDate = ActiveDocument.Sections["Casket Margin"].Shapes["Service_Date^qiqlbx^showname^a"];
    if (objServDate.SelectedList.Count > 2){
         Alert("Please select only two dates");
         return;
    ActiveDocument.Sections.Item(txlMe.Text).Qiq_onControlClick(this.Parent,this)
    ActiveDocument.Sections["Results_Merch Detail"].Limits["Service Date"].Operator = 11
    ActiveDocument.Sections["Results_Detail"].Limits["Service Date"].Operator = 11;
    I tried it with and without an extra semi-colon at the end of my line. Is that the right way to tell it to apply it to more than 1 Result??
    Worked with this for hours now and can't find whatever else is hidden which tells the QIQfIlter Date to refresh this NEW query/result when chosen.
    I tried to make sure all Filter items exist in the new query's Request line, one was missing. i haven't gone back to Dash Studio since then and re-saved, does THAT matter? I saved the .BQY and re-processed, still no luck.
    can anyone help? I'm desperate for suggestions.
    Thank you!
    Karen

    This has been resolved. The main thing that kept it from working was I kept launching the Dashboard Studio after I was in Design mode so any time I got to the QIQ Filters setup screen it looked like cryptic code and there was nothing to alter or play with to try and force the filters to take effect, so I never changed anything.
    This time I launched the Dashboard Studio while accidentally in regular mode, blessing in disguise. on Step 1 of the wizard I chose QIQ Filter Properties from the configuration drop down list which pops up the Local Filters setup window, now in place of code syntax there was english-like words & action items for me to play around with so I chose my new result set from the drop down list and highlighted all the limits and clicked "Set Filters". Presto, that did it.
    Also I had to make sure all the columns referenced in the QIQ drop down lists and pick list was in my request line in the Query & Result section, repeat the above, and it's all working great now.
    Thanks,
    Karen

  • How to count records from 2 tables and show in RDLC Report

    hi all,
    its being a one day searching for the solution but No Luck.
     I have two SQL tables tblstudetail and tblfeereceiptdetail.
    i just want to count records from both tables and show in RDLC report.
    I tried SQl Query Like This:
    select a.session, a.course,
    Count(CASE a.ADstatus WHEN 'OK' THEN 1 ELSE 0 END ) AS Admission,
    Count(CASE s .I_receiptstatus WHEN 'OK' THEN 1 ELSE 0 END) AS Feeprint
    from
    tblstudetail a
    FULL join
    tblfeereceiptdetail s on s.studentID = a.studentID
    where a.session = '2015' AND s.Fsession = '2015' AND a.adcat = 'Regular'
    GROUP BY a.session,a.course
    ORDER by a.course
    The result Show the Same Value in Both columns
    Session    Course      Admission       FeeDetail
    2015          B.A. I               275              275
    2015          B.A. II              307             307
    2015         B.A. III             255            255
    2015          B.Sc. I             110             110
    2015           B.Sc. II           105            105
    2015          B.Sc. III            64               64
    Actully I want to Count How many ADMISSION have been Taken(FROM tblstudetail) and How many FEE RECEIPT have been Print (From tblfeereceiptdetail).
    please guide me for this as soon as possible.
    thanks in advance...

    I am counting 'OK' in both the table columns I.e 'ADstatus' in tblstudetail and 'feereceiptstatus' in tblfeereceiptdetail
    please suggest me

  • Counting records after a query

    I am running a query and I want to display the number of records retrieved during the query. I have researched the COUNT_QUERY built-in and tried to assign the value returned by this built-in to a variable. (It doesn't work.) I have used the the following statement within the WHEN-BUTTON-PRESSED trigger for a Push Button on my form:
    SELECT COUNT(:BLOCK.ITEM)
    INTO :BLOCK.ITEM2
    FROM DUAL;
    This statement is not providing a valid number for the number of records returned.
    Is there a function that I can use to count the number of records returned from a query?

    Create a display item to hold the count value. Then open the data block properties and under advanced database set precompute summaries to "yes". Then in your display item properties set the summary function to count; the summarized block to the block_name; and summarized item to any block item you would like to count.
    Hope this is clear and what you are looking for.
    Cheers.

  • Problem when Counting results of a query

    Hi all
    In our application, we use the Toplink Essentials Queryframework API to create queries because of JPA limitations.
    Now I have a problem: I want to count the results of a existing query, i.e. I have a ReportQuery and I want to count the results of it.
    I tried the following:
    ReportQuery query = ...
    ReportQuery countQuery = new ReportQuery(Pivot.class, builder);
    countQuery.addCount(COUNT,
    ExpressionBuilder.from("id", builder.subQuery(query)));
    countQuery.setShouldReturnSingleValue(true);
    return Integer.valueOf(session.executeQuery(countQuery).toString());
    Now it seems that Toplink executes the query but the result is not correct, i.e. the count result is NOT the same as the number of results in the original query.
    The subquery may contain group by's, a where clause and so on...
    Anyone has an idea how to count the number of results of another query in Toplink?
    It should have the same affect as a simple sql "select count(*) from (select ...)" query.
    Regards
    Michael

    Not exactly sure what your doing, what does the original ReportQuery select?
    You probably want to do something like the following:
    originalQuery...
    ReportQuery countQuery = new ReportQuery(Pivot.class, countBuilder);
    countQuery.addCount("id");
    countQuery.setSelectionCriteria(originalQuery.getSelectionCriteria());
    You may need to also call rebuildOn() if you reuse the same selection criteria from a different query.
    i.e.
    countQuery.setSelectionCriteria(originalQuery.getSelectionCriteria().rebuildOn(countBuilder));
    James : http://www.eclipselink.org

  • Question about creating multiple output  files from same query

    I have a query like this:
    select * from emp;
    ename empno deptno
    Scott 10001 10
    Tiger 10002 10
    Hanson 10003 20
    Jason 10004 30
    I need to create multiple output files in xml format for each dept
    example:
    emp_dept_10.xml
    emp_dept_20.xml
    emp_dept_30.xml
    each file will have the information for employees in different departmemts.
    The reason I need to do this is to avoid executing the same query 200 times for generating the same output for different departments. Please let me know if it is practically possible to do this.
    Any input is greatly appreciated.
    Thanks a lot!!

    You can write a shell script to generate the multiple spools files for the same output. Below script may helps you.
    #====================
    #!/bin/bash
    n=0
    while [ $n -le 20 ]
    do
    n=`expr $n + 1`
    sqlplus -s system/manager <<EOF
    spool emp_dept_$n.xml
    select count(1) from tab;
    spool off
    EOF
    done
    #====================

  • FROM Clause Query and Invisible records :(

    HI:
    My form has a block based on a FROM clause query (QUERY DATA SOURCE TYPE).
    This works fine with no errors. Count hits suggests that it is retrieving records but my Item is not displaying the records. I have nine records in total but all fields are blank even though I can 'scroll' through the nine (invisible) records.
    Strange, any ideas people ?
    thanks.
    N.

    Thanks you for the reply but its not the cause of the 'probem'. My items are in a multi record block ( I have tried single item bock / No Items displayed 1 etc..) but to no avail.
    The strange thing about it is that I can Message(:blk.item) and the value displays on the Message bar but there are no values displayed in the Canvas Item at runtime ????? Very strange or does someone know something I dont.
    I can even scroll to the end of the record set ( 9 recs).
    I have never caome across this before has anyone else ?
    Thanks
    N.

  • Changing DEFAULT_WHERE of a FROM CLAUSE Query (with group by)

    I have a Data Block of type FROM CLAUSE Query.
    The Data Source Name is
    SELECT A2.NAME,A2.EMPLOYEEID,A1.ORGID,A1.FSCLYEARID,A1.STATUS,COUNT(*) AS COUNTER
    FROM S_PLC10300 A1,S_PLC50200 A2
    WHERE A1.EMPLOYEEID=A2.EMPLOYEEID
    GROUP BY A1.ORGID,A1.FSCLYEARID,A1.STATUS,A1.EMPLOYEEID,A2.NAME,A2.EMPLOYEEID
    I have a Query Area with text items which i use to change the DEFAULT_WHERE Property.
    My problem is that i can' t put in the DEFAULT_WHERE a field that doesn't belong to the SELECT Clause. Is there a way to achieve this?
    Maybe changing the whole Data Source Name at runtime ?
    Thanks

    As I said i have a block with FROM clause query:
    SELECT A1.ORGID,A1.FSCLYEARID,A1.STATUS, A1.EMPLOYEEID, A2.NAME,A2.EMPLOYEEID
    FROM S_PLC10300 A1,S_PLC50200 A2
    WHERE A1.EMPLOYEEID=A2.EMPLOYEEID
    GROUP BY A1.ORGID,A1.FSCLYEARID,A1.STATUS,A1.EMPLOYEEID,A2.NAME,A2.EMPLOYEEID
    i use the following code:
    set_block_property(BLOCK,DEFAULT_WHERE,'A1.TRNSDATE>=:QUERY_BLOCK.TRNDATE);
    What i think the code will do is change the FROM Clause Query to:
    SELECT ... WHERE A1.EMPLOYEEID=A2.EMPLOYEEID AND A1.TRNSDATE>=:QUERY_BLOCK.TRNDATE
    GROUP BY ...
    A1.TRNSDATE is a valid field of table A1.
    I can' t add TRNSDATE to my SELECT clause because i will have to add it to the GROUP BY clause.
    Hope i made more sense this time.
    Thanks

  • URGENT : online views for from clause query

    Hi all,
    I do not know why this query does not return any rows ! There are two online views in the from clause of the query . Each query returns rows , but when I include them in the from clause query then no rows are returned :
    Here are the results of each online views :
    select rdv_id,typerdv_id,count(rdv_finalite) nb_ok from rdvs where rdv_finalite='OK' group by rdv_id,typerdv_id;
    RDV_ID TYPERDV_ID NB_OK
    41 1 1
    select rdv_id,typerdv_id,count(rdv_finalite) nb_ok from rdvs where rdv_finalite='KO' group by rdv_id,typerdv_id;
    RDV_ID TYPERDV_ID NB_OK
    41 1 1
    And here is the query with the two online views in the from clause query :
    select to_char(r.rdv_date_effective,'Month') mois,ok.nb_ok nbok,ko.nb_ko nbko
    from rdvs r,
    (select rdv_id,typerdv_id,count(rdv_finalite) nb_ok from rdvs where rdv_finalite='OK'
    group by rdv_id,typerdv_id) ok,
    (select rdv_id,typerdv_id,count(rdv_finalite) nb_ko from rdvs where rdv_finalite='KO'
    group by rdv_id,typerdv_id) ko
    where r.rdv_id=ok.rdv_id and ko.rdv_id=r.rdv_id
    order by mois DESC;
    aucune ligne sélectionnée
    So where is the problem in my query ?
    Thank you very much

    For the first query here is the result :
    RDV_ID TYPERDV_ID NB_OK
    29 1 1
    For the second query :
    RDV_ID TYPERDV_ID NB_OK
    41 1 1
    Sorry

  • Grouping rows from a query

    Hi everyone!
    I want to know if it's posible to group the rows from a query into a unique row. Example:
    SELECT Field_1 FROM Table_1
    Returns the following fileds:
    Field_1
    A
    B
    C
    D
    I would want to modify my query so that the result obtained would be a single row containing all the others. In the previous example the result would be "ABCD".
    Thanks in advance. Best regards,

    -- For anyone who wants to test this,
    -- just copy this entire post as is,
    -- save it to a .sql file, then start that file.
    -- Before doing this,
    -- make sure that you don't already have
    -- a table named table_1 that would be dropped
    -- or a .sql file named query.sql that would be overwritten.
    -- If you do, then change the names below to avoid any conflicts.
    -- In order to understand what the code is doing,
    -- please read all of the comments included in this file,
    -- as not everything is displayed when you run it.
    -- I have gone into great detail with this
    -- because I have posted similar things before
    -- and a lot of people have total missed the fact
    -- that it is not a static query,
    -- that the results are dependent upon the number of rows,
    -- and that it works for any number of rows,
    -- even when the number of rows is unknonwn.
    -- test data:
    DROP TABLE table_1
    CREATE TABLE table_1
      (field_1 VARCHAR2 (1))
    INSERT INTO table_1 (field_1)
    VALUES ('A')
    INSERT INTO table_1 (field_1)
    VALUES ('B')
    INSERT INTO table_1 (field_1)
    VALUES ('C')
    INSERT INTO table_1 (field_1)
    VALUES ('D')
    COMMIT
    SELECT * FROM table_1
    -- Running the code below will create and start
    -- a file named query.sql which will contain the query below,
    -- which will produce the results below that:
    -- query that will be created:
    -- SELECT MAX(DECODE(ROWNUM,1,field_1,NULL))                                      
    -- ||MAX(DECODE(ROWNUM,2,field_1,NULL))                                           
    -- ||MAX(DECODE(ROWNUM,3,field_1,NULL))                                           
    -- ||MAX(DECODE(ROWNUM,4,field_1,NULL))                                           
    -- FROM table_1 GROUP BY NULL;                                                    
    -- results that will be produced:
    -- ABCD
    -- Notice that in this example,
    -- there are only four values concatenated
    -- because there are only four rows in the table. 
    -- If there were more rows, it would concatenate more values. 
    -- The number of concatenated values
    -- is dependent upon the number of rows.
    -- The following dynamic sql uses a single query,
    -- which produces and executes a single query,
    -- whose number of concatenated values is dependent
    -- upon the number of rows in the table.
    -- Because the echo is set off in the first line,
    -- you won't see this code when you run it,
    -- just the query that it creates.
    SET     ECHO OFF FEEDBACK OFF HEADING OFF PAGESIZE 0 VERIFY OFF
    SPOOL   query.sql
    -- This is the start of the single query:
    SELECT  text
    FROM    (SELECT 1                                             AS orderby,
                    'SELECT MAX(DECODE(ROWNUM,1,field_1,NULL))'   AS text
             FROM   DUAL
             UNION
             -- This section is the part that dynamically creates
             -- one additional concatenated value
             -- for each additional row after the first row.
             -- This is just a subquery within the single query.
             SELECT rn                                            AS orderby,
                    '||MAX(DECODE(ROWNUM,'||rn||',field_1,NULL))' AS text
             FROM   (SELECT ROWNUM rn
                     FROM   table_1)
             WHERE  rn > 1
             UNION
             SELECT COUNT (*) + 1                                  AS orderby,
                    'FROM table_1 GROUP BY NULL;'                  AS text
             FROM   table_1)
    ORDER BY orderby;
    -- This is the end of the single query.
    SPOOL    OFF
    START    query
    SET      ECHO ON
    -- If you want to see the file containing
    -- the single query that was created, then just:
    -- SQL> EDIT query.sql

  • Count distinct  from a master table and sum from a detail

    Hello to all,
    I have  a query like as:
             select a,b,c,     SUM(fa.ip1) S1, SUM(fa.ip2)   S2
             FROM tab1 FI, tab2 FA
             where fi.x1 = fa.x1
             and fi.x2 = fa.x2
             group by    a,b,c;
    tab1's table is master table for tab2's table (one tab1 records there are   many tab2 records), (one to many relation)
    My question is, how can I get to sum of columns: ip1 and ip2 from tab2 Fa, with only count(how many) of rows of tab1? 
    Somethings similar to;
    Select a,b,c, count(distinct fi.x1, fi.x2 ) nrec_of_FI,   SUM(fa.ip1)S1, SUM(fa.ip2)   S2
    Thanks in advance

    Hi,
    Sorry, I can't tell what you want just by looking at code that does not do it.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    Perhaps you want to get the totals in 2 stages, like this:
    WITH  five_column_totals  AS
        select    a, b, c
        ,         fi.x1, fi.x2       -- For debugging only
        ,         SUM (fa.ip1)   AS prelim_S1
        ,         SUM (fa.ip2)   AS prelim_S2
        FROM      tab1 FI
        ,         tab2 FA
        where     fi.x1 = fa.x1
        and       fi.x2 = fa.x2
        group by  a, b, c
        ,         f1.x1, f2.x2
    SELECT    a, b, c
    ,         COUNT (*)             AS nrec_of_f1
    ,         SUM (prelim_s1)       AS s1
    ,         SUM (prelim_s2)       AS s2
    FROM      five_column_totals
    GROUP BY  a, b, c
    Notice that the sub-query called five_column_totals is essentially what you posted, except that there fi.x1 and fi.x2 are included in the GROUP BY clause.  That means the sub-query will hve a separate row for each distinct combination of x1 and x2, which you can COUNT in the main query, GROUPing only BY a, b and c.

Maybe you are looking for

  • HT1386 Syncing iTunes Apple ID on my iPhone 4

    Before I had an iPhone, I had an Apple ID.  When I got my iPhone I went to the Sprint store and they asked me what my ID was, I told them and they set that up on my phone.  This ID is not a legitimate email address, so Ihad to change it when I wanted

  • How to plot a graph from text file?

    This is driving me nuts! I would like to plot a list of numbers in a text file to a graph. Each munber is on a new line, like this - 345 356 378 379 345 etc. I managed to import the file and split it with the 'Spreadsheet to array' function but can't

  • FUS Update on 5508 in AP SSO (HA) mode, How to?

    Hi all, I want / need to upgrade the FUS on my AP SSO 7.4.100.0 cluster. How to do this? I can't find instructions on how to upgrade in AP SSO mode, nothing in, in the release notes. Thanks Willem

  • Photoshop album  starter edition not installed

    i downloaded adobe reader 8.1.1 and it said it would install the photoshop starter addition too. it does not seem to have done that. how do i install the photoshop album starter edition?? EAG

  • WHAT IS   Message System  Queue  Properties

    Hi   I gone thru this blog..  but i did't understood. what is the Message System  Queue Properties.. is this is available  from service pack 19  only..? first of all what is this.. and where can we use this... can anybody give me a  brief idea about