count

counting non-unique rows in table with additional criteria

Hi, I have a table USERS with the following fields date(datetime) email(varchar) provider(int) event(int) I am looking for how many records there are with the same email, which occur in a specific month with a specific provider. like for provider= x and month = y i want email occurs [email protected] 5 [email protected]...

How do I check if more than one record has been returned from DBI query in Perl?

Hi, I searched for this on the site already but couldn't locate anything that answered my question. Which brings me to the details: I am querying database using a simple select query, realistically (given the scenario) it should never return more than about 5 to 6 records. I just want to check if more than one has been returned. And if...

How to count and limit record in a single query in MYSQL?

I am searching for records in a table as follows: SELECT Id, Name FROM my_table WHERE Name LIKE '%prashant%' LIMIT 0, 10; Now, I am adding LIMIT to maintain my paging. But when user searches for word 'prashant' then total records I have is 124 for 'prashant'. But as the limit applied to the query so it only fetches 10 records in my PH...

SQL delete loop

I have a table of housing listings. I would like to keep a maximum of 10 listings per city. (Most cities have less than 10 listings). When I do this query: select city, count(city) as cityCount from tREaltyTrac group by city SQL returns: Acampo 1 Acton 1 Adelanto 20 Agua Dulce 1 Aguanga 1 Akron 19 Albany 12 Albion 3 Al...

is there something faster than "having count" for large tables?

Here is my query: select word_id, count(sentence_id) from sentence_word group by word_id having count(sentence_id) > 100; The table sentenceword contains 3 fields, wordid, sentenceid and a primary key id. It has 350k+ rows. This query takes a whopping 85 seconds and I'm wondering (hoping, praying?) there is a faster way to find all...

How do I add two count(*) results together?

I have two tables: Toys and Games. +--------------------+------------------+ | Field | Type | +--------------------+------------------+ | toy_id | int(10) unsigned | | little_kid_id | int(10) unsigned | +--------------------+------------------+ +--------------------+------------------+ | Field ...

How can I count the total number of MySQL queries used per page?

Is there a built-in function in PHP or MySQL that will provide the total number of MySQL queries used on a page? I've seen on a lot of sites (mainly forums) they have a message at the bottom saying something like "Page generated in 0.6 seconds with 20 queries". If there's nothing built in then I'll add something to my database class to ...

mysql count child table rows with condition

I have two tables: "user" -> "order" TABLE: user user_id ----------- u1 u2 TABLE: order order_id | user_id | flag ------------------------- o1 | u1 | fA o2 | u2 | fB Y need obtain all users counting how many times have orders with flag 'fA' RESULTS WHAT I NEED: user_id | orders ---------------- ...

Postgres: could an index-organized tables paved way for faster SELECT COUNT(*) FROM table

I find it cumbersome to create a trigger just to get the current total rows of the table without doing COUNT(*) FROM table. I'm thinking if their planned index-organized tables for Postgres 8.5 could make it possible? ...

accurate page view count

What is a good approach to keeping accurate counts of how many times a page has been viewed I'm using Django. Specifically, I don't want refreshing the page to up the count. ...

COUNT in a query with multiple JOINS and a GROUP BY CLAUSE

I am working on a database that contains 3 tables: A list of companies A table of the products they sell A table of prices they offered on each date I'm doing a query like this in my php to generate a list of the companies offering the lowest prices on a certain product type on a certain date. SELECT a.name AS company, c.id, M...

Displaying zero-valued data in an SQL Query?

I have the following two tables (simplified for this question): CREATE TABLE team ( teamID CHAR(6) NOT NULL PRIMARY KEY); CREATE TABLE member ( memberID CHAR(7) NOT NULL PRIMARY KEY, teamID CHAR(6) NOT NULL REFERENCES team(teamID) ); I also have the following query, which is to list the number of members in each team: SELECT tea...

Counting array elements in Perl

I need to get the total items in array, NOT the last id, none of both ways I found to do this works: my @a; # Add some elements (no consecutive ids) $a[0]= '1'; $a[5]= '2'; $a[23]= '3'; print $#a, "\n"; # prints 23 print scalar(@a), "\n"; # prints 24 I expected to get 3.. Thank you in advance. ...

How to increment a counter each page load (in PHP)?

I want a certain action to happen when a user has visited X pages of a site Do I have to store the counter externally (in a txt file or db)? I can't think of a way to set the counter to 0, then increment it each page load. The counter would always get reset to 0, or am I missing something obvious? ...

Find out how many users are online in PHP?

Every visit to my website updates a user's individual hit counter and updates a column for time() based on their ip address and id stored in a cookie. So when coming to output the data, what's a more efficient way of my following code with less database calls, as it's essentially a copy of itself: <? $last1Min = time()-60; $last5Mins = ...

item frequency count in python

Hi, I'm a python newbie, so maybe my question is very noob. Assume I have a list of words, and I want to find the number of times each word appears in that list. Obvious way to do this is: words = "apple banana apple strawberry banana lemon" uniques = set(words.split()) freqs = [(item, words.split.count(item)) for item in uniques] print...

SQL distinct and count

I have a query where I want to get distinct dates, the phone numbers associated with those dates, and a count of the phone numbers per date. For example, I have a database with dates and phone numbers and I want the result to be 9/2005 5554446666 3 9/2005 4445556666 1 10/2005 1112223333 1 11/2005 2223334444 ...

How can I count unique terms in a plaintext file case-insensitively?

This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file. I only need this for quick sanity-checking, so it doesn't need to be well-engineered. ...

SQL; Only count the values specified in each column

In sql i have a column called answer and it can either be 1 or 2, i need to generate an SQL query which counts the amount of one and twos for each month, i have the following query but it does not work: SELECT MONTH(`date`), YEAR(`date`),COUNT(`answer`=1) as yes, COUNT(`answer`=2) as nope,` COUNT(*) as total FROM results GROUP BY YEAR...

How do I formulate a query using the Symfony Plugin DbFinderPlugin to count grouped by columns?

I cannot figure out how to write the following query using the DbFinderPlugin 1.2.2 with Symfony and Propel: SELECT species, COUNT(*) FROM Bird GROUP BY species; Here is the DbFinderPlugin page I am rather new to the plugin, and I do love it so far, but this query has so far stumped me. ...