SQL Query in c#

后端 未结 1 1744
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 16:49

I might have a problem with my SQL query. In this query I\'m combining 4 different tables.

  • I have a table courses where general information is stor
相关标签:
1条回答
  • 2021-01-25 17:50

    Courses the employee hasn't taken.

    SELECT * FROM courses
    WHERE course_number IN (
        SELECT course_id FROM job_course
        WHERE course_id NOT IN (
            SELECT course_id FROM emp_courses
            WHERE emp_id = {someid}
        ) AND job_id = (
            SELECT job_id FROM employees
            WHERE emp_id = {user_input}
        )
    )
    

    Which employees still need to take a course.

    SELECT emp_name FROM employees
    WHERE emp_id NOT IN (
        SELECT emp_id FROM emp_courses
        WHERE course_id = {user_input}
    )
    

    Variant of above.

    SELECT emp_name FROM employees
    WHERE emp_id NOT IN (
        SELECT emp_id FROM emp_courses
        WHERE course_id = (
            SELECT course_id FROM courses
            WHERE course_number = {user_input}
        )
    )
    
    0 讨论(0)
提交回复
热议问题