0

我真的不知道如何查询这个。我的数据库中有以下内容

id,employee,jobsite1,stime,etime,lunchout,lunchout,lunchout,说明,材料,jobsite2,stime,etime,lunchout2,lunchout2,description2,materials2

这实际上重复了5次。当我从表中执行 SELECT * 时,就像一个魅力拉动我的所有数据(我将其导出到 xls 中进行编辑),然后我从 jobsite2、3、4 和 5 中获取所有信息并将其复制并粘贴到一行。所以基本上

ID, EMPLOYEE, JOBSITE,  , STIME,ETIME,LUNCHOUT,LUNCHIN, DESCRIPTION, MATERIALS
1,  CHRIS   , MYSITE,   , 9:00, 1:00 ,12:15,   12:45  , WORKED HERE, NONE
1,  CHRIS   , SECONDSITE, 1:15, 5:00 ,        ,       , WORKED HERE, NONE
2,  BOB     , MYSITE    , 9:00, 5:00 ,12:00   ,12:30  , WORKED HERE, NONE
3,  MIKE    , MYSITE    , 9:00, 2:00 ,12:00   ,12:30  , WORKED HERE, BOUGHT STUFF
3,  MIKE    , SECONDSITE, 2:00, 5:30 ,        ,       , DOING THIS , NONE

有没有办法在我不通过 excel 手动执行的情况下进行查询?使用也许加入?我从未使用过 JOIN,但听说过它,并且一直很好奇,一旦我有正确的查询设置,导出它会更容易吗?这有意义吗?

4

1 回答 1

3

如果我理解正确,您可以使用UNION

SELECT  id, employee, jobsite1, stime1, etime1, 
        lunchout1, lunchin1, description1, materials1
FROM tableName
UNION
SELECT  id, employee, jobsite2, stime2, etime2, 
        lunchout2, lunchin2, description2, materials2
FROM tableName
UNION
SELECT  id, employee, jobsite3, stime3, etime3, 
        lunchout3, lunchin3, description3, materials3
FROM tableName
UNION
SELECT  id, employee, jobsite4, stime4, etime4, 
        lunchout4, lunchin4, description4, materials4
FROM tableName
SELECT  id, employee, jobsite5, stime5, etime5, 
        lunchout5, lunchin5, description5, materials5
FROM tableName
于 2012-09-04T15:14:37.757 回答