We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [count]

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

47 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
49 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. ...
2
votes
2answers
804 views

Automatically updating a record using count() of another collection

I have been looking at the docs and searching for videos on my problem, but I find nothing. I have a db called HPDASH where I have 2 collections, scripts and serverList. My problem is that I want to ...
2
votes
1answer
339 views

Slow ranking values in MySQL

I have a table of around 30 million retail products, with various INT columns that describe sales counters and pricing at different retailers. I'm supposed to display well over 70 different rankings ...
2
votes
0answers
419 views

MySQL aggregation count performance

I have a table with about 30 million records, and I'm doing a query where I can group by field Year and count the results for that year. The table structure looks like: id | year | amount The query ...
1
vote
0answers
161 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(...
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 ...
1
vote
0answers
34 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
122 views

Efficient count query for consecutive time windows

I have a SQL Server Database: in one table, one of the columns represents the time of an event (of type datetime2(7)). Another column represents a product ID. My goal is to specify a flexible time ...
1
vote
0answers
1k views

Limit relation one to many or one to one

In a relationship one to many or one to one you can limit the relationship of the related table? For example, I have a table 'cliente' and another 'acct', each 'cliente' can have thousands (perhaps ...
1
vote
2answers
121 views

MySQL Count where all conditions evaluate to 1

What is the best way to get count for all the records, where case evaluates to one for all the conditions. I have the query as: SELECT uuid , COUNT( CASE WHEN (( dt = 1 or level0 = '...
1
vote
0answers
1k views

I can't divide 2 count(*) values without returning zero

The statement I'm using is for a KPI in Maximo and I currently have this statement: select (select count(*) from incident where incident.slanum = 'USERADMIN' and incident.actualfinish > incident....
0
votes
0answers
17 views

select rows and calculate number of rows based on parent column value

I have a total of three tables with a many-to-many relationship. 1.) users id | email ----------- 1 | usera@example.com 2 | userb@example.com 3 | userc@example.com 2.) accounts id | userId | ...
0
votes
0answers
30 views

MySQL Count rows of multiple tables

CREATE OR REPLACE VIEW organizedevent AS SELECT o.organizerID AS "Organizer ID", o.organizerName AS "Name", o.contact AS "Contact", COUNT(e.eventID) AS "...
0
votes
0answers
22 views

How to implement row count for REST API?

I’m building a REST API backed by PostgreSQL. I'm encountering something I don’t think is very niche, but I’m having trouble finding any discussion of it. Good REST API practice dictates that if a ...
0
votes
1answer
21 views

MySQL Count(Table1.ColId) Where IN (any of Table2.Col1 ,Table2.Col2)

I have 2 Tables Table 1 has Id, Name Table 2 has Id, Col1_IdVal, Col2_IdVal,Col3_IdVal,Col4_IdVal I would like simple solution for Count(T1.Id) WHERE T1.Id In (T2.Col1_IdVal,T2.Col2_IdVal,T2....
0
votes
0answers
68 views

How to get hit (number of possible results of a query) from a table with more than 100 million records in Postgres

We have a table X in postgres v11, where it has 5 columns like A B C D E. We all columns are indexed and there are all integer values. We have around, 100 milion records, but soon will turn into 800 ...
0
votes
0answers
24 views

Time wise user online count

I'm not a DB expert but i'm trying to get time wise user online count to show in a graph. I have manage to get online user count for current time but how to get for a time span ? i need each minute ...
0
votes
1answer
12 views

Help with optimizing Oracle Query - nested with count

I have 2 tables (Students and Cellphone). Columns in Students: StudentID, FNAME, PHONEID Columns in Cellphone: PhoneID, Phonename I want to create this: • Run a query to show the most popular ...
0
votes
3answers
74 views

SQL Join and Count

I have 3 tables in SQLServer that I want to join so I can count the number of times each SUBJ_NAME occurs for the ITEM_IDs in the LOAN table. CREATE TABLE SUBJT ( SUBJ_ID CHAR(4) PRIMARY KEY, ...
0
votes
1answer
243 views

MySQL - Split results of count function into columns derived from a separate column

The title seems a bit confusing, but I am struggling to put down what I need this query to do so best to explain it. I have 3 tables in my database (Using MySQL Workbench), but for this query I'm just ...
0
votes
1answer
39 views

Distinct counts from large table are too slow

I have a table with 1.2 billion rows. The table has 60-70 columns, the vast majority of which are empty. The table is indexed on subscription_id, among other indexes. My query is: SELECT count(...
0
votes
1answer
24 views

Count Total Transaction each specific row even if 0

I have a 3 Columns namely: Payment Channel Payment Name Total Transaction The Total Transaction will be the COUNT of each Payment Channel and Payment Name. In the Payment Channel, values have PC01-...
0
votes
1answer
154 views

How to get Average value from one row if have zero or null values in mysql

I'm new in mysql. I want to ask something about get average value from one row in mysql when have a null or zeros value on them. the image below assuming my table And I want to get the average from ...
0
votes
1answer
47 views

Counting and grouping over multiple OUTER JOINs

I'm creating a view of advertisement logs (impressions, clicks, and clicks per impression). I have a simple table structure and some working queries but I'm having some trouble composing these into a ...
0
votes
1answer
36 views

mysql query to fetch group wise count

I am having mysql tables like below tbl_source_1 SRC_ID_1 | SOURCE_NAME_1 1 | ABC 2 | DEF 3 | GHI tbl_source_2 SRC_ID_2 | SOURCE_NAME_2 1 | NAME_1 2 | NAME_2 3 ...
0
votes
1answer
47 views

Efficient way to check for number of records more than a limit from a table in SQL Server

I came across queries that can most efficiently get the total sum of the records in the table. However, i want to group the records in a table by a column and check if the count of the records is ...
0
votes
1answer
33 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 ...
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, ...
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
1answer
55 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 ...
0
votes
1answer
481 views

mongo cluster collection count showing different every time

I had a replica set earlier which I have converted to cluster. Current configuration is: 3 shard 4 router 4 config server When I am trying to get count of one of collection sometime it is showing ...
0
votes
1answer
162 views

Limit the number of results but show how much would be returned

I have a big problem in T-SQL with large amount of data where I need to limit number of returned rows to 200K but also to show the number of rows that would be returned. It is needed to be done under ...
0
votes
1answer
38 views

Mysql query to get count result and group by

I've got three tables with different records for users, User username | realname | date evn-az-3ju john 11/2012 03:09:40 p.m. jwyvm_rdyt steve 12/2012 ...
0
votes
2answers
207 views

How to improve query count execution with mySql replicate?

For my report I have to use count queries (name 'user_activity' for example) and then group by by another column (user_type) in another table (user table). And its really time consuming when it ...
0
votes
0answers
63 views

How to use COUNT() properly with a 3 table join

I have a database where I have driver details, their assigned routes and their stop locations. For each driver on the database I need to find the location (or locations, as it could be more than one) ...
0
votes
0answers
458 views

Slow count using postgresql?

I have a query that is executed frequently with a few of the same conditions EXPLAIN ANALYZE SELECT COUNT(*) FROM "comments" WHERE "comments"."published" = 't' AND "comments"."user_id" = 15 AND (...
0
votes
0answers
50 views

Efficiently counting Clicks grouped by Week as well as all sub-totals

I have a large and slow database 'LargeSlowTable' which records clicks by users. I only have read permission, not write, so I cannot use Global Temporary Tables. I want to count the number of clicks, ...
0
votes
1answer
55 views

How do I get only those values that has related elements from other table?

I have three tables for a social network: companies, users and countries. Users belong to Companies and Companies have a Country. All tables have their own id column. Table users has a company_id FK ...
0
votes
1answer
53 views

Group-by in an Oracle database

on an Oracle database. If I make an: select id,id_operator,denumire,cod_fiscal,loc_den,str from rap where is_punct_lucru=1 and id_operator in ( select id_operator from rap where ...
0
votes
0answers
841 views

count rows with same value and get column from other table

I'm trying to count product numbers for a period of time there are three tables. invoice (table) Column Column ------------------------------------------- |invoicenumber ...
0
votes
2answers
117 views

SQL Performance: COUNT or extra attribute?

If I want to count the number of a multivalued attribute, which way is faster: a) using COUNT(attribute) on a whole table or b) adding an extra attribute which counts these stored values (to be ...
0
votes
0answers
123 views

Paging via Number of Result Record vs COUNT(*)

I have been working on fixing a piece of code for a customer that has been very slow for them. I have made that fix, and thats all lovely, but I noticed something odd in the paging. When the query ...
-1
votes
1answer
37 views

Month on Month count to determine variance of table growth

Good Afternoon Team, Hoping you can help me . Every month i get a count of records associated to a table. What i would like to do is month on month calculate the % variance (between jan vs feb, feb ...
-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 - ...
-1
votes
3answers
785 views

Query to return zero entries with COUNT

I have a problem with one task. I need to display various information through two diferent queries.(or one if it could be possible) The table has these fields. Location is set to x +------------+-----...
-2
votes
1answer
1k views

multiple counts of the same column SQL

currently using the following SQL to get multiple counts from the same column but my results are returning all the same SELECT act.OWNER_LOGIN, COUNT(CASE WHEN act.X_ACTIVITY ='Call' THEN 1 ELSE 0 ...
-4
votes
0answers
35 views

Count terrible slow

I have the following issue. This query on my database runs in 2 sec select events.*, events.start AS eventFrom, events.title AS ...