Questions tagged [count]

Count refers to the number of objects in a collection. It's also a commonly-used SQL function that counts the number of rows.

Many programming languages offer some sort of count, length or size fields and/or methods for arrays and collections, e.g. PHP's count($array) or Java's array.length.

COUNT() is also commonly-used SQL function that counts the number of rows in a table. It is an ANSI SQL aggregate function that returns the number of times the argument is encountered per group (or if no non-aggregate columns, per query). Commonly, the argument is specified as * - ie COUNT(*) - simply counting the rows. It can be used to count distinct values of a column like this: COUNT(DISTINCT MY_COLUMN)

Reference

See also:

21460 questions
3
votes
4 answers

Oracle group/count query

I have the following two tables: TableOne ======== Id1|ColA1|ColB1|ColC1|ColD1|ColE1 -------------------------------- 1| AFoo|BFoo |CFoo | DFoo| EFoo 2| AFoo|BBar |CFoo | DFoo| EFoo TableTwo ======== Id2|ColA2|ColB2|ColC2 --------------------- …
user973479
  • 1,629
  • 5
  • 26
  • 48
3
votes
2 answers

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?
Hao
  • 8,047
  • 18
  • 63
  • 92
3
votes
3 answers

SQL Query - count - max

I cant manage to come up with a query for a problem. I have three tables CREATE TABLE institute ( iid INT PRIMARY KEY, sign VARCHAR(127) UNIQUE, city VARCHAR(127) NOT NULL, area INT CHECK (area>0)); CREATE TABLE desease ( did…
Onica Radu
  • 183
  • 2
  • 4
  • 11
3
votes
3 answers

Mysql SELECT COUNT(*) OR SELECT 1? PDO

It has long been known that PDO does not support COUNT(*) and a query like below would fail as it doesn't return any affected rows, $q = $dbc -> prepare("SELECT COUNT(*) FROM table WHERE id = ?"); $q -> execute(array($id)); echo $q ->…
NovacTownCode
  • 65
  • 1
  • 7
3
votes
2 answers

How to count the number of row keys for a particular column_family in Cassandra (read details)

I am trying to load data from SQL to No-SQL i.e Cassandra. but somehow few rows are not matching. Can somebody tell me how to count the number of row keys for a particular column_family in Cassandra. I tried get_count and get_multicount, but these…
Nish
  • 650
  • 1
  • 8
  • 14
3
votes
1 answer

Multiple counts in one query

This query doesn't work. Can someone help me please? $query = "SELECT COUNT(WHERE Name='george') AS george_total, COUNT(WHERE Name='michael') AS michael_total, COUNT(WHERE Name='mike') AS mike_total FROM users WHERE Banned IS NOT '1'…
Jordy
  • 4,719
  • 11
  • 47
  • 81
3
votes
5 answers

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…
Jeff
  • 717
  • 2
  • 8
  • 19
3
votes
6 answers

SQL Server NULLABLE column vs SQL COUNT() function

Could someone help me understand something? When I can, I usually avoid (*) in an SQL statement. Well, today was payback. Here is a scenario: CREATE TABLE Tbl (Id INT IDENTITY(1, 1) PRIMARY KEY, Name NVARCHAR(16)) INSERT INTO Tbl VALUES…
John Gathogo
  • 4,495
  • 3
  • 32
  • 48
3
votes
6 answers

how does count in c++ stl set work?

So, I'm trying to check whether a particular object is already present in the set. For this, I use the count() method. Now, it doesn't seem to return the right answer. Let me explain the problem a bit more clearly -- I have declared a class this way…
shashydhar
  • 801
  • 3
  • 8
  • 26
3
votes
3 answers

SQL - Count number of changes in an ordered list

Say I've got a table with two columns (date and price). If I select over a range of dates, then is there a way to count the number of price changes over time? For instance: Date | Price 22-Oct-11 | 3.20 23-Oct-11 | 3.40 24-Oct-11 | …
Jama
  • 295
  • 4
  • 9
3
votes
1 answer

Count wikipedia results

I'd like to get the number of Wikipedia pages matching a condition. e.g. "house" --> 1,200 pages "man" --> 13,000 pages "university college" --> 360 pages Among many other ways, I can do this by indexing Wikipedia with Lucene, but that's pretty…
Mulone
  • 3,603
  • 9
  • 47
  • 69
3
votes
2 answers

Select value of largest groups / most common values in bridge table in T-SQL

I have a table which represents a "Contract" between two rows in another table. Given the data below, how can I get the most common Distributer for each EndUser? Contracts EndUserId | DistributerId | StartDate | EndDate…
andrej351
  • 904
  • 3
  • 18
  • 38
3
votes
4 answers

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

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…
BorisTheBulletDodger
3
votes
1 answer

Batch Script - Count instances of a character in a file

Using a batch script (.bat file) in windows xp, how would I go about reading a text file and finding how many instances of a character exists? For example, I have a string with the…
Anthony Miller
  • 15,101
  • 28
  • 69
  • 98
3
votes
7 answers

In PHP can I get the total number of case statements in a switch statement?

Is there a way to return the total number of (case) instances there are in a switch statement? Something like this: $id = $_GET['id']; switch ($id) { case "item1" : $data = 'something1'; break; case "item2" : $data = 'something2'; …
John
1 2 3
99
100