Skip to content

Tag: count

GROUP BY and COUNT in PostgreSQL

The query: Returns n records in Postgresql: I just want to retrieve the number of records returned: 6. I used a subquery to achieve what I want, but this doesn’t seem optimum: How would I get the number of records in this context right in PostgreSQL? Answer I think you just need COUNT(DISTINCT post_id) FROM votes. See “4.2.7. Aggregate Expressions”

SQL count(*) performance

I have a SQL table BookChapters with over 20 millions rows. It has a clustered primary key (bookChapterID) and doesn’t have any other keys or indexes. It takes miliseconds to run the following query However, it takes over 10 minutes when I change it like so or Why is that? How can I get select count(*) to execute faster? Answer

How to count number of records per day?

I have a table in a with the following structure: I would like to know how I can count the number of records per day, for the last 7 days in SQL and then return this as an integer. At present I have the following SQL query written: However this only returns all entries for the past 7 days. How

Oracle Count even if nothing is there

So i have this query: It will return stuff from place and then d is another table describes. It will get the number of reviews the place has and the average rating. This works perfectly fine as long as there is something in the describes table. How can i go about getting the stuff that does not have anything in

How to COUNT duplicate rows?

I want to be able to create a histogram out of a tuple containing two integers values. Here it is the query: For this input: Would be: How can I create a histogram of those values? In other words, how can I count how many times a row has a duplicate? Answer The question leaves room for interpretation. This test

Count number of users from a certain country

I have a table of users, and in this table I have a country field telling where these people are from (i.e. “Sweden”, “Italy”, …). How can I do a SQL query to get something like: Users select their countries from a list I give to them, but the list is really huge so it would be great to have