count

Django - Count a subset of related models - Need to annotate count of active Coupons for each Item

I have a Coupon model that has some fields to define if it is active, and a custom manager which returns only live coupons. Coupon has an FK to Item. In a query on Item, I'm trying to annotate the number of active coupons available. However, the Count aggregate seems to be counting all coupons, not just the active ones. # models.py cla...

How can I count the number of items using the FIND function in MATLAB?

How can I use the function FIND to count the number of items of a given value instead of using a loop? For example, in the array item below there are 3 occurrences of the number 23, 2 occurrences of the number 22, and 2 occurrences of the number 20. .... for i=2:n if item(i-1)~=item(i) nItem21(i)=1; else nItem21...

TSQL Optimal / Acceptable table column count

What is the optimal / acceptable column count when you are designing a table that serves as a datastore for huge forms to be filled? ...

mysql count help

I am trying to count the number of rows in a table that have an area, how can I achieve this, I currently have this query written, SELECT DISTINCT area FROM cv WHERE status = 'SHOW' AND is_complete = 'TRUE' ORDER BY area ASC This query currently returns, area ------------------ West Yorkshire Lanchashire What I am w...

How to get the results with count 0 too with Hibernate?

I am using the Projections.rowCount() function on Hibernate, but it will only return the counts greater than 0. I need to get the list with the 0 count too. This is the function supposed to give me the count but it only returns counts greater than 1. public List<Object[]> getCuentaPorEnlotar() { DetachedCriteria criteria = casosEst...

Dmoz/Monster algorithme to calculate count of each category and sub category?

I have to create a browse page like monter.com or dmoz directory. My problem is the counts for each category. What's the best practive to do a similar thing? I am using PHP/MySQL Thx! ...

SQL get polls that specified user is winning

Hello all and thanks in advance I have the tables accounts, votes and contests A vote consists of an author ID, a winner ID, and a contest ID, so as to stop people voting twice Id like to show for any given account, how many times theyve won a contest, how many times theyve come second and how many times theyve come third Whats the faste...

Row counting a JOINed column without affecting the returned rows?

It's a bit difficult getting my problem into a short form, so I apologise if the title doesn't make sense. Anyway, here is the problem: $query = ' SELECT issues.*, comments.author AS commentauthor, favorites.userid AS favorited FROM issues LEFT JOIN comments ON comments.issue = issues.id AND comments.when_posted = issues.when_upda...

SQLite count(*) how to get the result?

i've done this code to count the numbers of row in a db int rows = 0; if (sqlite3_open([[SqliteManager getDBPath] UTF8String], &database) == SQLITE_OK) { const char *sql = "select count(*) from artheca"; sqlite3_stmt *countstmt; if(sqlite3_prepare_v2(database, sql, -1, &countstmt, NULL) == SQLITE_OK) { ...

PostgreSQL count() and arrays

I have a table that looks like this: episodes ------------------------------------------------------------ id (PK serial) | show_id (int4) | episode_number (int2[]) ------------------------------------------------------------ 1 | 1 | {1} 2 | 1 | {2} ...

PHP - How to count fields in row?

How can I count how many fields there are in this row: $row['number'] while ($row = mysql_fetch_array($result)) { echo ' <td class="alt">'.$row['number'].'</td> $number = $row['number'] } ...

SQL Count distinct times with a 30 minute difference

I'm trying to find a SQL query that will count the number of distinct start times that are at least 30 minutes different. I have a number of employees that are paid a credit when they start work on at least three distinct times in a week, where the start time is at least 30 minutes different from the other start times. For example: se...

C++ count time overcoming 72 minutes range of clock_t

Hello, I'm trying to count the execution time of part of my application, but since I need to get milliseconds, and I need to get long execution times too. I'm currently using clock_t = clock() from ctime, but it has a range of only 72 minutes I think, which is not suitable for my needs. Is there any other portable way to count large exec...

Database design: Running totals of row counts

I have run into the following situation several times, and was wondering what best practices say about this situation: Rows are inserted into a table as users complete some action. For example, every time a user visits a specific portion of a website, a row is inserted indicating their IP address, username, and referring URL. Elsewhere,...

Postgresql count substring with a "where" clause

I am trying to count a substring, while matching different values from another column. The following statement gives me a syntax error on the where clause. Is the following even possible, and what is the correct syntax? select address, datacenter, ifdesc, count(substring(ifdesc, 'Ethernet0/*') where ifadminstatus ...

why is Count taking extremely long in one Postgres Database but not another

I have two Postgres databases. In one I have two tables, each with about 8,000,000 rows, and a count on either of them takes about a second. In another database, also Postgres, there are tables that are 1,000,000 rows, and a count takes 10s, and one table thats about 6,000,000 rows, and count takes 3min to run. What factors determine ...

How do I build a flexible counter with 1000+ rows but few reads in Google App Engine?

I have a list of users that only administrators can see (= few reads). This list also displays a count of the number of users in the datastore. Because the list could grow larger than 1000 my first thought was to avoid a normal count() and instead use a sharded counter. However, the problem is that the admins also have access to various...

counts of groups

I have a table with a text column that contains various bits of data. For example Hello world This is a piece of text Q1 3 New text Q2 2 Q1 2 Q1 3 More text The bits of text trhat have Q1 at the start are pieces of voting data and are the bits I am interested in. How can I write a query that gets counts of voting data ...

Inner join with count() on three tables

Simple and fast question, i have those tables: //table people | pe_id | pe_name | | 1 | Foo | | 2 | Bar | //orders table | ord_id | pe_id | ord_title | | 1 | 1 | First order | | 2 | 2 | Order two | | 3 | 2 | Third order | //items table | item_id | ord_id | pe_id | title | | 1 | 1 | 1 | ...

How do I get the index of the largest list inside a list of lists using Python ?

I am storing animation key frames from Cinema4D(using the awesome py4D) into a lists of lists: props = [lx,ly,lz,sx,sy,sz,rx,ry,rz] I printed out the keyframes for each property/track in an arbitrary animation and they are of different lengths: track Position . X has 24 keys track Position . Y has 24 keys track Position . Z has 24 ke...