English 中文(简体)
页: 1 学历:如何让所有雇员了解情况,以及所有课程名称,以显示雇员所选课程
原标题:SQL Query: How to get all employees with their information and all courses names with showing the courses that the employee has taken them

I have the following tables in my database: Employee Table which consists of Name, Id , Organization Course Table which consists of CourseName, CourseId

每个雇员都可以学习许多课程,因此我们有许多与男子的关系。 为此,我将另设一个表格,即:employee_course,由雇员_id和课程_id组成。

My problem now is: How to get all the employees with their information and all courses names with showing the courses that the employee has taken them?

其结果应给我如下:例如,如果A雇员在服务器管理演播室上第1和第2号课程,我就应当:

雇员A. . 课程表

雇员A. . 课程编号2

我问:


SELECT     dbo.employee.Name, dbo.employee.BadgeNo, dbo.employee.Division, dbo.employee.Organization, dbo.courses.CourseName, 
                      dbo.employee_courses.courseId AS Expr1
FROM         dbo.courses LEFT OUTER JOIN
                      dbo.employee_courses ON dbo.courses.CourseID = dbo.employee_courses.courseId RIGHT OUTER JOIN
                      dbo.employee ON dbo.employee_courses.employeeId = dbo.employee.BadgeNo
最佳回答

2. 以这种形式提出质询:

SELECT
  *
FROM
  employee
LEFT JOIN employee_courses ON (
  dbo.employee_courses.employeeId = dbo.employee.BadgeNo
)
INNER JOIN courses ON (
  dbo.courses.CourseID = dbo.employee_courses.courseId
)

我先把雇员放在桌面上,这肯定是一栏,然后留给另外两栏。

Edit: fixed joins.

问题回答
SELECT e.EmployeeName, c.CourseName
FROM employee e
LEFT JOIN employee_courses ec on ec.EmployeeID = e.BadgeNo
LEFT JOIN courses c on c.courseId = ec.courseId

页: 1 我先看一栏名,但我先检查一下,而原则是没有意义的。

If you want more specific responses, I d suggest you post some DDL representing the key elements of your database, along with a few INSERTs of representative test data.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签