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 7957881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:19:53+00:00 2026-06-04T04:19:53+00:00

I am trying to create an SQL query which returns a Business name. Employees

  • 0

I am trying to create an SQL query which returns a Business name. Employees are members of Teams AND of Groups, Teams and Groups are members of Businesses.

I need to select the Business which has employees which are a members of a Team, which has certain attributes as a whole.

How do I go about writing SQL to return the Businesses which have a member to senior member ratio of %? ex Team A has only 20 senior employees out of 100 team members; so it fails and the Business which Team A belongs to should be returned.

I know I need to group Employees together based on their Team, but somehow need to count the Employees who have SENIOR=YES against SENIOR=NO AND return the business they belong to. Ideas?

They are MS Access tables which contain some sensitive information, but you can think of the tables as being set up as follow:

tblBusiness: BID, BName
tblTeam: TID, TName, TBusRef
tblEmployee: EID, EName, ETeamRef, EBusRef, ESenior

I’ve literally tried all manner of SQL: I’ve done everything from nested SQL to heavy aggregation to expressions containing count. The closest (I think) I’ve gotten is:

SELECT tblBuisiness.BName FROM tblBuisiness
GROUP BY BName HAVING (
COUNT(SELECT DISTINCT tblEmployee.ETeamRef FROM tblEmployee WHERE ESenior=-1)
/
COUNT(SELECT DISTINCT tblEmployee.ETeamRef FROM tblEmployee)
< 0.5
)

Now this one might have syntax errors (was on the clipboard) but I went through it 100x and the closest I got was “cannot have expression in agregate “COUNT()/<0.5” “

If TeamA of Business1 has 20 senior members and 80 regular members, then this query is to return Business1.

  • 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-06-04T04:19:54+00:00Added an answer on June 4, 2026 at 4:19 am

    Perhaps:

    SELECT * 
    FROM (
      SELECT 
        e.EBusRef, 
        Count(e.EID) AS EmpCount, 
        Sum(Abs([ESenior])) AS Senior, 
        [Senior]/([EmpCount]/100) AS [%Senior]
      FROM tblEmployee AS e
      GROUP BY e.EBusRef) q
    WHERE q.[%Senior]<=50
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to execute a sql query which will create a new table
I'm trying to create an SQL query in PHP to update a table. Is
I am trying to create a linq 2 sql in EF 4.0 query like
i am trying to create sql procedure or function that need to find duplicate
I'm trying to create an SQL statement that joins two tables and returns a
I'm currently trying to create a T-SQL, which runs through a list of deliveries
I am trying to optimize a sql query which is using order by clause.
I am trying to create a products table running the following SQL query: CREATE
I am trying to write a SQL query that returns rows from a table
I am trying to create query which orders by child collection's property. It is

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.