我正在尝试从2个不同的表中进行选择,这会产生如下输出:
Punchdate | EmployeeCode | Name | Punch_in | Break | Lunch | Second_start | Break | Punch out
---------------------------------------------------------------------------------------------
11.08.2005 1021 John Smith 7:00 9:00 12:00 1:00 3:10 4:30
dbo.Punchintervals
employee(dbo.punchintervals.employee=dbo.employee.objid)
intime
outime
department/*(dbo.punchintervals.department = dbo.emprole.objid*/
/*(intime column has all the punches form all the departments,they need to be sorted trough the department column)*/
dbo.employee
employee/*(dbo.employee.objid=dbo.punchinterval.employee)*/
name
code
dbo.emprole
objid/*objid is just a vule example 10 (dbo.emprole.objid = dbo.punchinterval.department)*/
name/*(name of the role example: quality control, punch out, lunch,break)*/
到目前为止,这是我的最后一次尝试
SELECT TOP (100)
PUNCHDATE,CODE,name
,(
SELECT [sitewatch].[dbo].Punchinterval.INTIME
FROM [sitewatch].[dbo].Punchinterval AS PunchIn
WHERE [sitewatch].[dbo].Punchinterval.DEPARTMENT = '10'
) AS Startime
,(
SELECT [sitewatch].[dbo].Punchinterval.INTIME
FROM [sitewatch].[dbo].Punchinterval AS PunchIn
WHERE [sitewatch].[dbo].Punchinterval.DEPARTMENT = '11'
) AS break2
FROM [sitewatch].[dbo].Punchinterval,[sitewatch].[dbo].employee
答案 0 :(得分:0)
SELECT * FROM dbo.employee
JOIN dbo.Punchintervals ON dbo.punchintervals.employee=dbo.employee.objid
JOIN dbo.emprole ON dbo.emprole.objid = dbo.punchinterval.department