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
5 answers

Count number of objects in array that match another object

right now I'm doing something like this to match objects in an array: for (var key in users) { if (users[key].userID==session) { //do whatever } } but I need to figure out how many times this matches, if it only matches once, then I want it to…
Dylan Cross
  • 5,918
  • 22
  • 77
  • 118
3
votes
2 answers

How to find the homewrecker by counting *each* group by subsection?

Let's say I have a table of (mostly) faithful couples. The couples appear several times in the same table. You can tell who's faithful because Jack is always with Dianne, Fred is always with Ginger, etc. However, Tom, Dick, and Harry are each dating…
Sliced Bread
  • 158
  • 1
  • 7
3
votes
4 answers

MySQL count optimization

I want to decrease the load time from 2.5 secs for a mysql count query. All columns in the query have a index. SELECT COUNT(1) FROM song AS s JOIN song_text AS st ON(st.song_id = s.song_id) JOIN phpfox_user AS u ON(u.user_id = s.user_id) WHERE…
3
votes
3 answers

SQL; Only count the values specified in each column

In SQL I have a column called "answer", and the value can either be 1 or 2. I need to generate an SQL query which counts the number of 1's and 2's for each month. I have the following query, but it does not work: SELECT MONTH(`date`),…
Johnnny
3
votes
4 answers

method ruby return true or false

I want get from a method ruby true if every posts are followed for a people and false if not. I have this method: def number_of_posts_that_are_followed user_to_be_followed = User.find(params[:id]) #users whose posts, will be followed by another…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198
3
votes
7 answers

SQL count at least

I need to find the makers producing at least three distinct models of PCs. Result set: maker, number of models. My tables are Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) I have done this for now SELECT Product.maker,…
DPE
  • 218
  • 5
  • 15
3
votes
1 answer

Best way to get an object count in CoreData in iOS

as I have seen there are several possibilities to get an object count in core data(when I say an object count I mean the object count and just only the object count). If I set resultType to NSCountResultType, then what is better to do,…
e1985
  • 6,239
  • 1
  • 24
  • 39
3
votes
3 answers

Multiple Count On Same Column with Where like - MySQL

I'm trying to do multiple counts on the same column with different where like clauses. I have figured out the base Queries for each of my like clauses but I need to combine them to produce one result. select system_user, COUNT(details) from…
rreeves
  • 2,408
  • 6
  • 39
  • 53
3
votes
2 answers

Finding an element with max. no of appearing in SQL

I have the following table: id | year 10 | 2000 11 | 2001 10 | 2002 12 | 2003 11 | 2004 13 | 2005 10 | 2006 10 | 2007 According to id, since 10 appears most, the selection should give 10 for this…
Gary Leather
  • 281
  • 2
  • 6
  • 18
3
votes
5 answers

How to get row count of 2 different tables (and databases) in one query?

I got a database named accounts and account table inside of this database, Also I got the database named players and player table inside of this database. How can I get a rows count of this two tables in one query? I've tried this: SELECT …
Cyclone
  • 14,839
  • 23
  • 82
  • 114
3
votes
4 answers

How can I use MySQL to COUNT with a LEFT JOIN?

How can I use MySQL to count with a LEFT JOIN? I have two tables, sometimes the Ratings table does not have ratings for a photo so I thought LEFT JOIN is needed but I also have a COUNT statement.. Photos id name src 1 car bmw.jpg 2…
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
3
votes
3 answers

How do I count the number of times I ping a host in JSP?

My code is here from which I get result either true or false that weather it ping to the host I mention in it or not, try { InetAddress address = InetAddress.getByName("192.168.1.125"); boolean reachable=address.isReachable(10000)); …
Salman Raza
  • 1,635
  • 6
  • 18
  • 18
3
votes
5 answers

Count number of Not Null fields within a Row

Possible Duplicate: Count the Null columns in a row in SQL I've had a dig around for answers to this, but can't find either a working or suitable answer and I'm a novice with SQL. I've got a table containing teams for an event, and amongst other…
user1124503
  • 33
  • 1
  • 1
  • 4
3
votes
3 answers

I want to count all the rows for todays / yesterdays date based on a DATETIME - mysql+php

I have database "db2" with table "menjava" In table menjava have "id", "author" and "date_submitted" field id - auto_increment author - int(11) date_submitted - datetime I want to count all the rows for todays date and all the rows for…
Sašo Krajnc
  • 133
  • 2
  • 3
  • 11
3
votes
3 answers

MySql: Select by Count with Union or Joins

I need a way for page moderators to view the members of their page ordered by the total number of posts the user has on that particular page. The posts are stored in different tables such as polls, downloads, wiki, etc (like 15 tables). Each of…
bowlerae
  • 924
  • 1
  • 14
  • 37