SQL Server - Count the number of times the contents of a specified field repeat in a table

Timbo

What's the best way to 'SELECT' a 'DISTINCT' list of a field from a table / view (with 'WHERE' criteria) and alongside that count the number of times that that field content repeats in the table / view?

In other words, I have an initial view that looks a bit like this:

Initial Table/View

I'd like a single SQL query to filter it (SELECT...WHERE...) so that we are only considering records where [ORDER COMPLETE] = False and [PERSONAL] = Null...

Filtered out any TRUE values

...and then create a distinct list of names with counts of the number of times each name appears in the previous table:

Distinct list of names with Count field

*Displaying the [ORDER COMPLETE] and [PERSONAL] fields is redundant by this point and could be dropped to simplify.

I can do the steps individually as above, but struggling to get a single query to do it all... any help appreciated!

Thanks in advance,

-Tim

Jamie Pollard

This should just be the following

SELECT dbo.tblPerson.Person,
       COUNT(dbo.tblPerson.Person) AS Count
  FROM dbo.tblPerson
INNER JOIN dbo.tblNotifications ON dbo.tblPerson.PersonID = dbo.tblNotifications.AddresseeID
 WHERE dbo.tblNotifications.Complete = 'False'
   AND dbo.tblNotifications.Personal IS NULL
GROUP BY dbo.tblPerson.Person
ORDER BY COUNT(dbo.tblPerson.Person) DESC

You don't need your DISTINCT or TOP 100 PERCENT,

Here is a simplified fiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Repeat array rows specified number of times

From Dev

Repeat each item in a list a number of times specified in another list

From Dev

SQL Server column was specified multiple times

From Dev

Count number of times 2 distinct values appear in more than 1 row in SQL Table

From Dev

Count number of times string matches a field across multiple documents

From Dev

Count in s Table SQL Server

From Dev

SQL query to get number of times a field repeats for another specific field

From Dev

Count the number of times each members name appears in a table with a condition

From Dev

Count the number of times each members name appears in a table with a condition

From Dev

sql - show count of field from another table

From Dev

sql server count distinct value of a field

From Dev

SQL query to count the number of times a term appears if the term appears

From Java

Count the Number of Tables in a SQL Server Database

From Dev

How to count number of people in submission SQL Server

From Dev

FLWOR in Sql server count number of hits

From Dev

count the number of spaces in values in sql server

From Dev

SQL Server: Count number across columns

From Dev

FLWOR in Sql server count number of hits

From Dev

How to count number of people in submission SQL Server

From Dev

Repeat a Number N Times in an Array

From Dev

Get the number of same field from a table in SQL

From Dev

How can I repeat each text field in a column the number of times given in another column?

From Dev

count number of values in each field in awk, output table

From Dev

Count of Columns in temp table in SQL Server

From Dev

How to get the count of a join table in sql server?

From Dev

sql server, aggregate (count) on many columns in table

From Dev

SQL Server - Insert record count into table

From Dev

Make a copy of a table in the same database of SQL Server 2008 and then update the contents

From Dev

How to Count Number of in in a field

Related Related

  1. 1

    Repeat array rows specified number of times

  2. 2

    Repeat each item in a list a number of times specified in another list

  3. 3

    SQL Server column was specified multiple times

  4. 4

    Count number of times 2 distinct values appear in more than 1 row in SQL Table

  5. 5

    Count number of times string matches a field across multiple documents

  6. 6

    Count in s Table SQL Server

  7. 7

    SQL query to get number of times a field repeats for another specific field

  8. 8

    Count the number of times each members name appears in a table with a condition

  9. 9

    Count the number of times each members name appears in a table with a condition

  10. 10

    sql - show count of field from another table

  11. 11

    sql server count distinct value of a field

  12. 12

    SQL query to count the number of times a term appears if the term appears

  13. 13

    Count the Number of Tables in a SQL Server Database

  14. 14

    How to count number of people in submission SQL Server

  15. 15

    FLWOR in Sql server count number of hits

  16. 16

    count the number of spaces in values in sql server

  17. 17

    SQL Server: Count number across columns

  18. 18

    FLWOR in Sql server count number of hits

  19. 19

    How to count number of people in submission SQL Server

  20. 20

    Repeat a Number N Times in an Array

  21. 21

    Get the number of same field from a table in SQL

  22. 22

    How can I repeat each text field in a column the number of times given in another column?

  23. 23

    count number of values in each field in awk, output table

  24. 24

    Count of Columns in temp table in SQL Server

  25. 25

    How to get the count of a join table in sql server?

  26. 26

    sql server, aggregate (count) on many columns in table

  27. 27

    SQL Server - Insert record count into table

  28. 28

    Make a copy of a table in the same database of SQL Server 2008 and then update the contents

  29. 29

    How to Count Number of in in a field

HotTag

Archive