1 Replies - 599 Views - Last Post: 22 December 2017 - 10:56 AM

#1 bhdowning   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-October 09

Counting occurrences

Posted 22 December 2017 - 10:53 AM

Need some advice on a query.

Background:
A table contains a listing of containers and a product for each container. A container can have multiple rows however only one product per row.

example:

Columns are container, product

Container      Product
1              a
1              b
2              c
2              a
3              b
3              c


What I am looking for is an output give an output of each unique item a, b and c with how many times each of the items were together in the same carton.

Thanks in advance,

Is This A Good Question/Topic? 0
  • +

Replies To: Counting occurrences

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,466
  • Joined: 12-June 08

Re: Counting occurrences

Posted 22 December 2017 - 10:56 AM

Group by your columns and do a 'count' on product!

https://docs.microso...nt-transact-sql
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1