A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [count]

COUNT : an aggregate SQL function that is used to count the number of rows.

Filter by
Sorted by
Tagged with
1
vote
0answers
190 views

MySQL count rows of multiple tables for each user

I basically need this with some adjustments, I just can't seem to figure it out how to do it. I need to sum the rows of two tables, for example: SELECT student.StudentID, student.`Name`, COUNT(...
2
votes
1answer
57 views

where clause after limiting results

I have a question about getting results after limiting the rows. I don't have much experience with MySQL, but I'm trying to get results from a database where I need to do the where clause after ...
0
votes
2answers
59 views

Calcutation at SQL level

I have this query: SELECT * FROM ( SELECT COUNT(lead_status) as 'Pending files' FROM vw_file_registrationlist WHERE lead_status_id = "1" || lead_status_id="2" || lead_status_id="4" || ...
0
votes
2answers
69 views

Count all products (with qty > 0) group by all brands. But get aslo count zero for brand which have 0 products

I have table: brands brand_id name 1 Apple 2 Sony 3 Nokia 4 HTC products id brand_id qty 1 1 3 2 3 0 4 1 1 2 2 1 I need to ...
0
votes
1answer
43 views

Get two row counts from the same table [closed]

What I am trying to achieve is run both queries (below) at the same time. From one table rvsessions I need to get the count for the total amount of sessions(which is achieved by the number of times ...
0
votes
1answer
148 views

MySQL, would like to get both a field and a count inside GROUP_CONCAT

I can get a list of statuses that a tracking ticket has had, as well as the id of those statuses, as follows: SELECT t.id, t.name, GROUP_CONCAT( CONCAT(s.id, ':', s.name) ORDER BY s.id) AS ...
1
vote
2answers
835 views

Using COUNT in triggers before insert into table

I am new to MySQL and am struggling with triggers. Say I have a table called members with the following data MemberID(PK) (INT) | Name (VARCHAR)| 1 | Barry | and another ...
1
vote
2answers
206 views

SELECT i.c.w. a COUNT and INNER JOIN gives different results with string literals and numeric values when they are used in a WHERE clause

I have a MySQL query: SELECT p.informationProvider as pGLN, p.productID, p.productStatus FROM tblproducts AS p WHERE -- informationProvider is of type varchar(14) p....
-1
votes
2answers
105 views

MySQL Query can we count rows using php to reduce time of count(*) in a query or there is no difference?

Having the following queries, where the first query is returning a field of number of rows found, and the second returns the actual rows: First Query: SELECT count(*) as total FROM individual i ...
0
votes
1answer
34 views

select data from related tables and display their counts in the relating table

I have a table which stores data about an inspection. Inspections are carried out in a particular company belonging to an industry, located in a region. the inspections table has the industry_id field ...
-1
votes
1answer
45 views

Count comma seperated values in mysql ORDER BY clause

I have a table name products: id - pro_name - ip - date_created 1 - abc1 - 27.106.121.23,27.106.121.86 - 2018-08-15 13:32:00 2 - ...
0
votes
2answers
115 views

Calculate ticket sales by using SUM in SELECT clause

In this ticketing setup on dbfiddle, I am trying to calculate the ticket sales for a particular event by multiplying the ticket price and the total number of tickets sold for that event, based on ...
23
votes
3answers
18k views

How to select specific rows if a column exists or all rows if a column doesn't

I'm writing a script that gets a count of rows for a few tables, however for some tables I want to only get a count of rows where a flag is set (in this case active=1). Is there a way I can do this ...
2
votes
0answers
50 views

MariaDB running indefinitely on inner join with count

I am currently experiencing a very, very weird issue with a query in MariaDB. Our server experiences a "504 Gateway Timeout" quite often after a database upgrade, and I was investigating the issue. ...
1
vote
0answers
2k views

How to apply a condition on “count over partition”?

I'm using Oracle 11g. Assuming multiple consecutive entries (sorted by datetime) with the same place_id represent a single visit. With this table: datetime_id | user_id | place_id and I want to ...
0
votes
3answers
153 views

SQL Count function returning inaccurate results

I am trying to write a query in oracle to list the number of records contained in a single table filtered by multiple columns in the tablespace. Here is the query syntax I have come up with: SELECT ...
3
votes
2answers
443 views

MySql concurrency with COUNT

I Have a table with user_id and product_id. For my purpose, a particular user is allowed up to 5 rows only. To enforce this, I created such a SQL statement: INSERT INTO the_table (product_id, ...
2
votes
1answer
2k views

SQL query to get the user, counting the minimum number of records

I have an table with some records and a column LAST_EDIT_USER. If I want to select all users with the number of appearances for every user, I would do SELECT LAST_EDIT_USER,COUNT(LAST_EDIT_USER) ...
1
vote
2answers
38 views

Basic question about grouping and counts

I'm having trouble coming up with a query in MySQL. Suppose we have a table that logs an action by a user. User1 is a Doctor and is logged several times. User2 is a Doctor and is logged once. User3 ...
1
vote
3answers
818 views

SQL Server COUNT() seems to be ignoring WHERE [closed]

I am trying to set up a SQL Server query that lists the count of people signed up for tours during a conference event and then displays the total sum. This is my SQL code that is coming close, but it ...
11
votes
1answer
7k views

Postgres: count(*) vs count(id)

I saw in the documentation the difference between count(*) and count(pk). I had been using count(pk) (where pk is a SERIAL PRIMARY KEY) not knowing about the existence of count(*). My question is ...
1
vote
3answers
2k views

Is COUNT(DISTINCT PRIMARY_KEY) faster than COUNT(*)?

I haven't got a particular problem here, I'm just interested. One of my associates uses COUNT(DISTINCT(PRIMARY_KEY)) every time he needs to select all the data from a table (with 100m + rows) is it ...
3
votes
3answers
193 views

Index scan on UNIQUE index for count(*)

I've got a table t with ~23 million rows (4248 MB in size). There's a column row_id in it, with a not null constraint. And a unique index p1 on t(row_id). When I do select count(*) from t to count ...
0
votes
4answers
62 views

Help for grouping a field and taking total sum

I have a sorted data in a table F1 F2 F3 F4 A M X 1 A N Y 2 A P X 3 B M X 3 B N Y 1 B P X 5 but I want the sub count of values in F1 column for every row. ...
0
votes
1answer
45 views

SQL Server count value of column [closed]

I call the table is [vDemo] []1 i want count MaLC by TenNV, result is if record 13 MaLC is L then Count(x) = 16, Count(L) = 1
2
votes
3answers
40 views

Is it possible to combine these three join queries into one?

I would like to combine the counts of the stats by different hit_types into one query. Is that possible? MariaDB [db]> select allurls.id, count(s1.id) from allurls inner join stats s1 on allurls....
2
votes
2answers
2k views

COUNT(), GROUP BY and GROUP_CONCAT() together on MySQL

My question is quite simple. I just want to count events from each client and present them in a comma separated single row. I have this table: +----+----------------+ | id | event | +----+--...
0
votes
1answer
1k views

SQL query to count with subtraction from count of other sql table [closed]

I have 2 tables as below I column is common to both. Table 2 has FK from Table 1. I need to get the count of ID_Tag per BoxNo as result. Condition List all BoxNo and subtract the count if the ID_Tag ...
1
vote
2answers
4k views

Multiple COUNTs over the same column

I have a table (PostgreSQL 9.6) containing 2.6 million+ timestamped rows associated with account identifiers, and for any given identifier, I want to count the total number of occurrences as well as ...
1
vote
2answers
371 views

Postgres - How to get Multi-Count Query using a Where Clause for a Join Table

I have the following query that gets the counts across multiple tables that are joined: select count(distinct e.planningitemdata->>'receiverDuns') as supplierOrCustomer, count(distinct ...
0
votes
2answers
49 views

How to get a COUNT for both IN and NOT IN a table

I have a table that contains a master list of items and an associated table that contains a unique text string only on specific values (determined by the application that inserts the data). Example: ...
2
votes
1answer
569 views

Calculate quantity of tickets based on how many reserved using sub queries

I'm designing a database that will hold ticketing information. The 3 tables I use to track ticketing are tbl_ticket_type to the types of events an event can have tbl_ticket_count to keep track of ...
2
votes
3answers
4k views

Is there a way to find out how many times a stored procedure was invoked since last DB start

I am currently in a fairly mismanaged environment, where stored procs were introduced to the database over a few years and some versions became obsolete. Is there an easy way to figure out (preferably ...
2
votes
1answer
7k views

Counting unique (distinct) users per day

I am new topsql and am interested in counting the number of unique first time users per day. My table only has two columns- user_id (there can be multiple uses by one user per day) and start_time ...
6
votes
2answers
969 views

Help with this query

I have a person table. I also have a car table and books table. The car and book tables both have a foreign key back to person. I am trying to count the number of books and cars each person has. I ...
1
vote
0answers
35 views

problem using count in trigger phpmyadmin

how to record the number of column lastbuy_idrbch and lastsell_idrbch from table idrbch in my new table (test) using trigger and count function ?
1
vote
1answer
63 views

Count how many records belong to 2 categories in a n to n relation

I have a database containing articles whose schema is more or less the following: COLLECTIONS ( PK id ) > 1 : n > TOPICS ( PK id, FK collection_id ) > n : n > TOPICS_TO_ARTICLES( FK ...
3
votes
2answers
732 views

Getting the exact count of rows in Postgres database

Is there any way to get the exact row count of all tables in Postgres in fast way? Count(*) seems to run very slowly for larger tables. Is there a way to get an exact count from Postgres statistics ...
1
vote
2answers
536 views

Count even deleted rows

Is it possible to count even deleted rows in a SQL Server table? Let's say we have a table Contacts. I'll add 5 new contacts, and hit count on it. It should return value of 5. Now, when I delete a ...
8
votes
3answers
6k views

Speeding up Count(*) on large tables

We're using a Vendor App running on SQL Server Enterprise, and it has a rather annoying quirk of executing COUNT statements on the Items table while processing most financial documents (orders, ...
0
votes
2answers
2k views

SELECT COUNT of multiple column under the same table

Im blowing my brain on this one. I think I am making this harder than I need to. Im trying to run a mySQL query to SELECT a COUNT of members which have any values in any column. my example table is as ...
0
votes
1answer
54 views

How to speed up counting and filtering on table with a lot of columns and filter conditions?

I have TABLE_A in my database that has a lot of columns. Let's say there are 100 columns: COLUMN_1, COLUMN_2, COLUMN_3, .. COLUMN_100 There are so many columns not because of denormalized design, ...
5
votes
2answers
42k views

Join two tables and return data and count in a single query

I have two tables in an SQL Server database, one with two columns and one with four: tbl_email_list email_list_id int (PK) email_list_name varchar tbl_email-details email_uniq_id int (PK) ...
1
vote
1answer
1k views

Bitmap Heapscan is slow

I have 2 tables: mailings and form_responses. The form_responses table has a foreign key with the mailings table, so a mailing has one-to-many form_responses. What I want to do is calculate mailing ...
2
votes
2answers
10k views

Aggregate interval data to hourly

I am getting data for 15 minutes interval. I would like to aggregate this data to hourly.Can anybody advise how should i do this query to sum the interval values and display it?
1
vote
1answer
676 views

How to display all the dates in the date-range having group by dates?

Suppose I have a table called “products”: Productive product-name product-quantity created-date 111 ABC 10 1/10/2018 222 XYZ 20 ...
1
vote
1answer
42 views

COUNT for instances with no value

I have a query that looks for and counts orders that have been written in a medical record that have a specific display group SID. I have 8 medical centers and I want a count for all of them even if ...
1
vote
1answer
7k views

Select unique value pairs that occur (count) more than once inside a table

How can I retrieve an row with unique value pairs that occur more than once... Heres an example of what I'm what I am trying to.. SELECT column_fk_id1, column_fk_id2, COUNT(distinct column_fk_id1, ...
0
votes
1answer
56 views

Looking for another method to count in a single query

So, I found this article is very useful Join two tables and return data and count in a single query and here Single query to return counts over different IDs in a single record for some IDs or ...
1
vote
2answers
103 views

Count the total occurences for each day in given dates

I have this table and don't enough SQL to make a query to achieve the result shown in the image below. CREATE TABLE myDates ( id integer NOT NULL, startDate date NOT NULL, endDate date ...