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
4
votes
3 answers

total number of duplicates in oracle table

I have a table like below SUBJECT Years MARKS AB 1 20 AB 1 25 AC 1 20 AC 1 30 AC 1 40 AD 1 20 I only need count of duplicates (subject||Year), expected answer is 2 and not AB1 --…
user1627796
  • 53
  • 1
  • 1
  • 5
4
votes
2 answers

jQuery keyup event increase-"function" will set to 0

I've three input fields to "search" a JSON tree. If all three fields are filled and correct get the data from next JSON level. I count up a number through the keyup-event to get next data of a JSON tree. But every time all three fields are filled…
yckart
  • 32,460
  • 9
  • 122
  • 129
4
votes
3 answers

SQL: Getting the COUNT of one table and JOIN the others

I have a query that looks like such: SELECT COUNT(A.Value1) AS Count, B.id AS Id1, C.id AS Id2 FROM Table1 A LEFT JOIN Table2 B ON (B.Name LIKE '%UserInput1%') LEFT JOIN Table3 C ON (C.Name LIKE '%UserInput2%') WHERE A.Value1 LIKE…
matt
  • 2,857
  • 7
  • 33
  • 58
4
votes
1 answer

MySQL+PHP: optimise ranking query and count subquery

This is raw data, and want to rank them according to score (count(tbl_1.id)). [tbl_1] =========== id | name =========== 1 | peter 2 | jane 1 | peter 2 | jane 3 | harry 3 | harry 3 | harry 3 | harry 4 | ron So make temporary table (tbl_2)…
chloe
  • 119
  • 11
4
votes
2 answers

SQL count grouping every 2 hours

How can i counting and grouping every 2 hours ? i have a table like this: Id TheTime -- ------- 1 07/07/2012 08:49:02 2 07/07/2012 09:36:39 3 07/07/2012 10:36:39 4 07/07/2012 12:36:39 5 07/07/2012 13:36:39 how can i convert into…
user609511
  • 4,091
  • 12
  • 54
  • 86
4
votes
2 answers

MYSQL select where count > 1

Need to execute query to find rowns with 3rd column value count > 1. Example: Table: col1 col2 col3 ------------------------ 1. val1 val2 val3 2. val11 val21 val3 3. val12 val22 val31 4. val13 val23 val32 5. val14 …
Vadim Galanov
  • 87
  • 1
  • 1
  • 4
4
votes
2 answers

slow count(*) on innoDB

I have a table message_message with 3000000 records. when I make a count(*) query, It's very slow...: mysql> select count(*) from message_message; +----------+ | count(*) | +----------+ | 2819416 | +----------+ 1 row in set (2 min 35.35…
jeff kit
  • 119
  • 1
  • 7
4
votes
1 answer

SQL aggregate function subquery

What I want to do is count the number of rows returned by a subquery, essentially the following: select pp.prop_id, COUNT((select employee_id from employee e where e.ao1_hours > 0)) from proposal_piece pp group by pp.prop_id order by…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
4
votes
3 answers

Efficient use of SQL GROUP BY, SUM, COUNT

I have a table of products sales that may look as follows: product | amount | ptype | pdate p1 | 1.00 | sale | 01/01 p1 | 2.00 | base | 01/02 p2 | 1.50 | sale | 02/03 p3 | 5.25 |…
Daniel Vaca
  • 159
  • 2
  • 3
  • 15
4
votes
1 answer

MYSQL including values for dates with zero item counts

I'd like to count the total number of purchases as well as the purchases by item_id over time. In this example, a user can own an item and these items can be purchased by other users. An owner can't purchase their own item. The problem I'm having…
tim peterson
  • 23,653
  • 59
  • 177
  • 299
4
votes
1 answer

Oracle SQL return count(*) column along side of regular column?

In Oracle SQL, how do I return count(*) column along side of a regular column? What works: select count(*) from TABLE where username = 'USERNAME'; What I'd like to work: select username,count(*) from TABLE where username = 'USERNAME'; So I want…
Xonatron
  • 15,622
  • 30
  • 70
  • 84
4
votes
4 answers

sql server count of max values without subquery

I want to write a T-SQL query which returns not only the maximum value, but the number of rows having the maximum value. There must be a better way than what I have come up with --wrong way select LibraryBranchId, max(daysCheckedOut),…
user130582
  • 183
  • 1
  • 3
  • 6
4
votes
3 answers

jQuery - Count number/Get Index of rowspan rows

I'm trying to figure out how to get the index of the current rowspanned "row" (even though its the cell that is rowspanned). …
jao
  • 1,194
  • 1
  • 11
  • 17
4
votes
3 answers

SQL COUNT - Output table with two COUNT columns with differing WHERE clauses

I have the need to generate a report in Oracle APEX that is similar to the example below: PROJECT OPEN_ISSUE_COUNT CLOSED_ISSUE_COUNT W-1 3 1 X-2 1 2 Y-3 5 …
Spags
  • 531
  • 5
  • 13
  • 26
4
votes
3 answers

XSLT - loop, count, position() with variables

Apologies in advance - total novice here and struggling after reading pretty much every XSLT thread in here. So I desperately need several aspirins and your guidance!! I have three incoming parameters/variables that need to be processed using xslt…
PBB
  • 161
  • 1
  • 2
  • 9
First First 1 1 First 2 1