Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Get how meny registration and how meny users with one sql

Kan i get how many registration and wow meni users in one sql conection (tsql)
Tables
- office
- users (who meny users)
- Registration (who meny registrations)

One user can have meny registreations.

hompage utput:
office name, who meny registrations, who meny users

SELECT DISTINCT 
                      dbo.office.officeName, dbo.office.officeAdres, COUNT(dbo.registration.RealPoints) AS [who meny registrations]
FROM         dbo.office INNER JOIN
                      dbo.users ON dbo.office.office_id = dbo.users.fk_office_id INNER JOIN
                      dbo.registration ON dbo.users.user_id = dbo.registration.fk_users_id
GROUP BY dbo.office.officeName, dbo.office.officeAdres
ORDER BY a DESC

Open in new window

0
MickeC
Asked:
MickeC
1 Solution
 
reb73Commented:
Try -
SELECT 
	 dbo.office.officeName
	,dbo.office.officeAdres
	,COUNT(DISTINCT dbo.users.user_id) AS [how meny users]
	,COUNT(DISTINCT dbo.registration.RealPoints) AS [how meny registrations]
FROM
	dbo.office
INNER JOIN
	dbo.users ON dbo.office.office_id = dbo.users.fk_office_id
INNER JOIN
	dbo.registration ON dbo.users.user_id = dbo.registration.fk_users_id
GROUP BY
	dbo.office.officeName, dbo.office.officeAdres
ORDER BY
	1

Open in new window

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now