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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:06:46+00:00 2026-05-27T13:06:46+00:00

I have an existing SQL query that works fine in SQL Server, that I

  • 0

I have an existing SQL query that works fine in SQL Server, that I would like to make work in MySQL. I have cleaned it up a bit, and fiddled with the back-ticks for column / table names, etc. but cannot get it to work.

Here is the statement in question:

SELECT `EmployeeID`
FROM `Employee`
WHERE
(
   (
      SELECT COUNT(*) AS A
      FROM `TimeClock`
      WHERE (`EmployeeID` = `Employee.EmployeeID`)
         AND (`InOut` = 'True')
   ) > (
      SELECT COUNT(*) AS B
      FROM `TimeClock` AS `TimeClock_1`
      WHERE (`EmployeeID` = `Employee.EmployeeID`)
         AND (`InOut` = 'False')
   )
)

This should return any EmployeeID‘s that have more InOut = True than InOut = False in the TimeClock table.

Thanks.

  • 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-27T13:06:46+00:00Added an answer on May 27, 2026 at 1:06 pm

    This should provide you with the EmployeeId values where there are more values of InOut True than False

    SELECT e.EmployeeId
    FROM Employee AS e
    INNER JOIN
    (
       SELECT tc.EmployeeID
          , SUM(CASE
                   WHEN tc.InOut = 1 THEN 1 ELSE 0
                END) AS InOutTrue
          , SUM(CASE
                   WHEN tc.InOut = 0 THEN 1 ELSE 0
                END) AS InOutFalse
       FROM TimeClock AS tc
       GROUP BY tc.EmployeeId
    ) AS t ON e.EmployeeId = t.EmployeeId
    WHERE t.InOutTrue > t.InOutFalse
    

    The two alternatives I came up with show similar performance on my VERY SMALL unindexed test data. I would recommend you test them against your own data to see if they make any difference:

    This one is pretty much the same, but using total record count instead of InOutFalse.

    SELECT e.EmployeeId
    FROM Employee AS e
    INNER JOIN
    (
       SELECT tc.EmployeeID
          , COUNT(1) AS RecordCount
          , SUM(CASE
                   WHEN tc.InOut = 1 THEN 1 ELSE 0
                END) AS InOutTrue
       FROM TimeClock AS tc
       GROUP BY tc.EmployeeId
    ) AS t ON e.EmployeeId = t.EmployeeId
    WHERE t.InOutTrue > RecordCount - t.InOutTrue
    

    I am not sure if MySQL will require the CAST I used here, but SQL Server did. (That is what I tested these with) It could not perform a SUM on a BIT column.

    SELECT e.EmployeeId
    FROM Employee AS e
    INNER JOIN TimeClock AS tc ON e.EmployeeId = tc.EmployeeId
    GROUP BY e.EmployeeId
    HAVING SUM(CAST(tc.InOut AS INT)) > (COUNT(1) - SUM(CAST(tc.InOut AS INT)))
    

    If all three perform similarly, it then comes down to personal preference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing SQL Server 2005 database that runs our accounting/inventory application. We
I have an existing mysql query that I need to add to and I'm
I have a stored proc on an existing 3rd party application (SQL 2005) that
I would like to export a ad hoc Select query result sets from SQL
The way that SQL server seems to be optimising a query is causing it
I have an existing SQL 2005 stored procedure that for some reason, outputs its
Ok, I have a SQL query that I'm trying to generate that will combine
I have quick question for you SQL gurus. I have existing tables without primary
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I have existing java code and need to create Design Document based on that.

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.