Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:47:36+00:00 2026-05-31T15:47:36+00:00

Please help me with the following situation: In SQL Server 2008 I have a

  • 0

Please help me with the following situation:

In SQL Server 2008 I have a database with the tables:

  • Installations (id, name) which is unique for a given system
  • Products (Id, name) which are installed on a system

And because a system has more products and the same product can be installed on multiple machines there is InstallationXProduct table withe their ids.

Another table Usages (usageid, productid, date etc) is linked to a product to keep track of product usages.

I need a script to link Installation, Products and Usage count for each Installation-Product pair, e.g.

Installation 1 Product A    2
Installation 1 Product B    3
Installation 2 Product A    1
Installation 2 Product C    2

Thank you for any help

Later EDIT:

Tables:

  • Installation: InstallationID, InstallationName
  • Product: ProductID, ProductName
  • InstallationXProduct: InstallationID, ProductID
  • Usage: UsageID, DateRecorded, ProductID

Set up data:

Insert into Installation values(1,'A')
Insert into Installation values(2,'B')

Insert into Product values (1,'P1')
Insert into Product values (2,'P2')

Insert into InstallationXProduct values (1,1)
Insert into InstallationXProduct values (2,1)
Insert into InstallationXProduct values (1,2)
Insert into InstallationXProduct values (2,2)
Insert into Usage values(1,getdate(),1)
Insert into Usage values(2,getdate(),2)
Insert into Usage values(3,getdate(),1)

Query to select:

select I.InstallationID, P.ProductID, count(U.UsageID)
from Installation I 
join InstallationXProduct IXC on I.InstallationID = IXC.InstallationID
join Product P on P.ProductID = IXC.ProductID
join Usage U on U.ProductID = P.ProductID
group by I.InstallationId,P.ProductID

returns:

1   1   2
2   1   2
1   2   1
2   2   1

After reading this light version I think I understand why it is not possible to split the usages in products and installations, there is no way I can tell whether usage one was recorded on product 1 from installation 1 or 2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:47:38+00:00Added an answer on May 31, 2026 at 3:47 pm

    If you need to count the rows in Usages, then something like this might be of help:

    SELECT
        InstallationName = i.Name,
        ProductName = p.Name,
        UsageCount = COUNT(u.*)
    FROM
        dbo.Installations i 
    INNER JOIN
        dbo.InstallationXProduct ixp ON i.InstallationId = i.Id
    INNER JOIN
        dbo.Product p ON ixp.ProductId = p.Id
    INNER JOIN
        dbo.Usages u ON u.ProductId = p.Id
    GROUP BY
        i.Name, p.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please can someone help? I have the following code which uploads a file to
Please help! I couldn't figure it out how to map the following situation: I
Please help regarding the following issue. I have enabled the Block popup option in
Please help me out with an algorithm for the following problem - Given a
Please kindly help me in the following, I have $sub = C:\views\sght\gzad\text\hksdk\akldls\hool.java = C:\views\sght\bdsk\text\hksdfg\sdjks\same.java
I need help with C programming. I have the following situation: struct Product {
Please, We have the following situation: Component X that divides a request file into
I must have done something very stupid which has caused the following situation. Basically
i have the following errors - please help me to find the error: 9
please help with the following:(using rails 3 and jquery) In my view i have:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.