Count the number of records between two key values (BTREE)

How can I count the number of keys between two values?
I'm using python driver, and BTREE access method.
====>
ideally what I want is to average a whole time-series data set (the intervals can change) to a given number of points. The keys are the time stamps and the values are the data that needs to be averaged. I need to count the number of records between two time stamps so that I can divide that number by the number of points i need, and average the data. What is the best way to do this?  Or should I just keep the intervals for the time stamp constant and use RECNO access method?
Thank you
(first post btw.. and why aren't there many people in stackoverflow who answer Berkeley DB questions?)

BDB is an embedded db and it does not have any internal counters or statistics that you could grap to use for this.    You will need to do it manually.
You can create a cursor, grap the records you want, each time you get the next record you bump a counter.
If you are using RECNO, you can use a cursor to get the record number of the record (DB_GET_RECNO), and if all you data is in
sequentail records with no missing records you can figure out the total count by take last rec # - initial rec # + 1 to get a total count.
If you switch over to the SQL API, you can issue a SQL query to give you a count.  Select count(*) Where .......
Since you have to grab the data anyway, then best may be to count records as you go along.
thanks
mike

Similar Messages

  • SQL to count the number of days between two dates

    Does any one have or know how to count the number of days/weeks between 2 dates.
    I have thought about using MONTHS_BETWEEN, but do not know how to make it accurate down to one day?
    Any suggestions would be appreciated.

    here are the different queries I came up with to do this, you may want to check it for perticular cases involving Sun and Sat as start and end dates.
    select to_number(to_char(to_date('21-JUL-00','dd-mon-yy'), 'ww'))
    - to_number(to_char(to_date('10-JUL-00','dd-mon-yy'), 'ww')) from dual;
    select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-1, 'Sunday')
    - Next_Day(to_date('10-JUL-00','dd-mon-yy')-1, 'Sunday'))/7 from dual;
    select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-6, 'Sunday')
    - Next_Day(to_date('10-JUL-00','dd-mon-yy')-6, 'Sunday'))/7 from dual;
    null

  • How do I count the number of records returned in the CMIS query

    How do I count the number of records returned in the query CMIS?
    SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
    Euler Homero

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

  • I wanted to know how do you calculate the number of days between two dates

    i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.

    thanks..
    I solve my problem as
    public class MyExample {
        public static void main(String a[]) {
            String stdate = "2009-03-01";
            java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
            java.sql.Date preDate = java.sql.Date.valueOf(stdate);
            System.out.println(currentDate);
            System.out.println(preDate);
    //        int dateCom = preDate.compareTo(currentDate);
    //        System.out.println(dateCom);
            long diff = currentDate.getTime() - preDate.getTime();
            int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
             System.out.println(days);
    }

  • Applescript - how can I count the number of records in a Word data source?

    I have written a script in AppleScript to open Word and then perform a mail merge from a data source and everything is working fine.
    One thing I want to do but am struggling with is to return the number of records in the mail merge.
    I am trying things like:
    get last record of datasource of mydatasource
    and also haven't been able to find anything in the AppleScript 2004 Word Reference Guide.
    Can anyone help as I have been searching the web and trying things all day and I am sure it can't be difficult.
    Thank you.

    I don't think there is an automatic way to get a line count, but I don't have any problem just counting the lines on a page. Maybe some more information about what you are trying to do and why you can't do it would help someone to come up with a helpful suggestion.

  • How to count the number of records retreived through a query?

    Dear All
    I want to find the total number of records retreived for a particular query .
    does BW provide any internal count function , which can solve my requirement??
    if yes, please provide some details.
    Thanks.
    Regards,
    Pandurang.

    hi pandurang
    when u see the contents of a particular cube
    RSA1->Infocube->manage->contents
    there is a option "Output number of Hits"
    An extra keyfigure is created displaying the number of records rolled up
    Aggregating the column might just solve ur issue
    Try
    Regards
    Akshay

  • Count the number of records

    Hi all,
    I have a BEx report that displays a list of empnos and their details based on a selection. Now I want to count the number of recrods that were selected and display the total number of records that were selected. How can this be done?
    Thanks,
    Sam

    Dear all,
    Thanks for the suggestions. Actially I had solved it in another way.
    As suggested by Sharma, I had used a CKF as count, But i did not want the empnos to come as the rows with 1 displayed across each row.
    I was trying to bring a summary in there.
    So I had created a structure in Rows and in the structure created a new selection and in that selection included Employee.
    This solved the problem that I was facing.
    Thanks everyone for your time and effort!!
    Cheers,
    Sam

  • Count the number of records in a group

    Hi ,
    My requirement is to display in the BI reprt - records in Order Entry Line Items based on several conditions on the fields.
    If the above conditions do not returm any records ,show an error message - NO DATA FOUND.
    1.checked in standard RTF templates where its a simple example as if :not(//servicereq).
    But ,my RTF has serveral conditions on the group.
    2.Is there a way to take a count of records in the group which statisfy the given condotions,so that I can checkif count = 0 .dislay message.
    Apreciate your help.
    Regards.

    Ummmmm...no I didn't, hate to admit it.
    Added the declaration to the 2 percentage formulas. Now I do get results for the percentage...they are just wrong. Only pattern I've found is that if the running total of Int or Ext is 1, the percentage is 11.39. If it is 2, the percentage is 22.78 and so on.
    Each percentage is a multiple of 11.39 depending on the respective running total calculation. Maybe you can see what I have obviously missed.
    NAME........TOTAL.......TOTAL Int........% Int........TOTAL Ext........%Ext
    Burberry........20..............4..................45.56.............16 ..............182.23
    Cellarosi.......11..............1 .................11.39.............10................113.90
    Chalkley.......19..............2..................22.78.............17................193.62

  • How to calculate the number of months between two string as yyyymm

    Dear all,
    I have two month string like yyyymm e.g. 201003 -- 201105. Now I want to calculate the number of months bertween these two month string? How can I do that? Thanks.

    888099 wrote:
    Hi,
    Hope this will help :
         public static void main(String[] args) {
              Calendar cal1 = new GregorianCalendar(2010, 02, 01);
              Calendar cal2 = new GregorianCalendar(2011, 04, 01);
              int years = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
              int months = cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
              System.out.println("number of months : "+Math.abs(years*12 + months));
         }Or with only Strings :
         public static void main(String[] args) {
              String s1 = "201002";
              String s2 = "201104";
              int years = Integer.valueOf(s1.substring(0,4)) - Integer.valueOf(s2.substring(0,4));
              int months = Integer.valueOf(s1.substring(4)) - Integer.valueOf(s2.substring(4));
              System.out.println("number of month : "+Math.abs(years*12 + months));
         }Edited by: 888099 on 28 sept. 2011 05:49Full code solutions will not help the OP, he will be back here with a different Date question. Posters here try to nudge the OP to figure out the solution himself.

  • (Repost) CR 8.5 I need to count the number or records 0

    - - Crystal Reports 8.5 - -
    I have two fields.
    Qty Shipped and Qty Backordered.
    I want to calculate the percentage of orders shipped.
    Something like:
    Count ({CIT_PT_RO_Fulfillment;1.QtyShip}) > 0
    Count ({CIT_PT_RO_Fulfillment;1.QtyBackorder}) > 0
    But I know these aren't correct as they return the value of True...
    Then I'll take those two fields and calculate the percentage shipped...
    Can someone help me with this?
    Thanks
    Kelvin

    Try this
    if count({CIT_PT_RO_Fulfillment;1.QtyShip})>0 then
    ((Count ({CIT_PT_RO_Fulfillment;1.QtyShip})-Count ({CIT_PT_RO_Fulfillment;1.QtyBackorder}))/Count ({CIT_PT_RO_Fulfillment;1.QtyShip})*100
    Regards,
    Raghavendra

  • How to calculate the number of records in Multiprovider

    Hi Experts
    I have created a report based on the multiprovider (Consist of Cube and ODS)
    I need count the number of records inside the multiprovider, how can i do it in the reporting level
    Regards
    Santosh

    Hi,
    You can use calculated key figure with replacement path variable.
    Follow This:
    1) From the context menu of the Key Figure directory, choose New Calculated Key Figure.
    2) From the context menu for the Formula Variable, choose New Variable.
    3) Choose the Processing type as Replacement Path.
    4) In the next screen, select the Characteristic Info Object based on which the number of documents is to be displayed in the report (For example: Document Number / Order Number).
    5) Choose Next.
    In the Replace Variable with drop down box, choose Attribute Value.
    In the Attribute drop down, select Characteristic Reference (Constant 1).
    6)Choose Next.
    On the Save Variable page, an overview of the settings made for the variable will be displayed.
    Confirm the entries and Choose Finish.
    7) If the Formula variable is directly assigned to the Calculated Key Figure, a warning Calculated Key Figure is not defined correctly will be displayed while executing the Query.
    8) Properties of Calculated Key Figure dialog box, assign a Technical name for the CKF.
    9) set the Time of Calculation to After Aggregation.
    Hope this will help you.
    Cheers,
    DK
    Edited by: Debasish Khaitan on May 14, 2009 1:03 PM

  • How to fetch records between two seq uence numbers?

    We have thousands of records with seq uence numbers in the oracle database, we need to retrieve a number of records between two seq uence numbers, i.e. to retrieve records between 100 and 200 seq uence numbers. Could some one help me to find a query to fetch records.
    I'll be waiting for your response..
    Edited by: sumant on Jul 27, 2010 12:42 PM

    Is this is what you are looking for?
    SQL> create table tab1 (id number);
    Table created.
    SQL> insert into tab1 values (1);
    1 row created.
    SQL> insert into tab1 values (2);
    1 row created.
    SQL> insert into tab1 values (3);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from tab1;
            ID
             1
             2
             3
    SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
      2  from tab1;
    RANDOM_NUMBER
               43
    SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
      2  from tab1;
    RANDOM_NUMBER
               39
    SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
      2  from tab1;
    RANDOM_NUMBER
               13 This will generate a random number that will be greater then the maximum value in the table and lower then the maxvalue + 50. Having the range starting from maxvalue in the table you will never get a number generated which already exists in the table.
    As you see in the above number genrated they are all between 4 and 53.
    If you want to increase the range from where the number are generated just increase the value 50 that I used in the query.

  • Determine the number of records in a file

    I want to analyse record types from a large input file and so far have managed to extract different groups and created the relevant files. All I want to do now is count the number of records in each file so I can produce a report showing the different types but cannot figure out how to do this, I know it will be simple but I cannot get any command to accomplish this, help please!

    in applescript, there are a few ways to count patterned text.  if (as jeffrey suggests) each record is a separate line, then you can use the following:
    set textContents to read "/path/to/file.txt"
    count of paragraphs of textContents
    if records are determined by some other process (such as a special delimiting character or phrase) you can use text items (replace the @ sign with the special character or phrase):
    set textContents to read "/path/to/file.txt"
    set {oldTID, my text item delimiters} to {my text item delimiters, "@"}
    set theCount to count of text items of textContents
    set my text item delimiters to oldTID

  • Get number of hours between two dates and two hours using factory calendar

    Hello all,
    I have the following requirement: I need to calculate the number of hours between two dates and two hours (start date- finish date and start hour-finish hour) or timestamps using a factory calendar. I must program it on CRM environment.
    Does anybody know a function module that makes it?
    Thanks in advance.
    Carmen

    Please check function module DURATION_DETERMINE.
    - April King

  • How to count the number of Fridays and Saturdays between two dates

    Hi every one ... If we want to count the number of Fridays and Saturdays between two dates, how would we do that ? !
    Dates are ( 11-Feb-2010) to (19-May-2010)
    how to do it in SQL
    Edited by: khalidoracleit on Jul 28, 2010 5:51 AM

    some nice coding here, I'm still amazed with what some people can do with "connect by". But I agree with some statements here that this can take "time", and to be honest, it's funny to see it working, but if you do not have a computer, just a calendar and some paper, would you go for "counting" so there must be a better solution?
    The best working math in here is done by Aketi Jyuuzou, who writes so good English that I wonder why he still insists that he doesn't ;-)
    Anyhow I "translated" that code to English, and I really like that math. Math is math and data is data.
    ALTER SESSION SET NLS_DATE_LANGUAGE='ENGLISH';
    WITH my_dates AS (
    SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100519','yyyymmdd') end_date FROM DUAL
    UNION ALL
    SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100214','yyyymmdd') end_date FROM DUAL
    UNION ALL
    SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100213','yyyymmdd') end_date FROM DUAL
    UNION ALL
    SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100212','yyyymmdd') end_date FROM DUAL
    SELECT to_char(start_date,'DD.MM.YYYY') start_date,to_char(end_date,'DD.MM.YYYY') end_date,
           to_char(start_date,'DAY') start_weekday,to_char(end_date,'DAY') end_weekday,
           end_date-start_date day_difference,
           (next_day(end_date,'FRIDAY')-7
           -next_day(start_date -1,'FRIDAY'))/7+1
           +(next_day(end_date,'SATURDAY')-7
           -next_day(start_date -1,'SATURDAY'))/7+1 as count_of_fr_and_sat
    FROM my_dates;
    START_DATE END_DATE   START_WEEKDAY                        END_WEEKDAY                          DAY_DIFFERENCE         COUNT_OF_FR_AND_SAT   
    11.02.2010 19.05.2010 THURSDAY                             WEDNESDAY                            97                     28                    
    11.02.2010 14.02.2010 THURSDAY                             SUNDAY                               3                      2                     
    11.02.2010 13.02.2010 THURSDAY                             SATURDAY                             2                      2                     
    11.02.2010 12.02.2010 THURSDAY                             FRIDAY                               1                      1                      -- andy

Maybe you are looking for