SQL查询每日出勤记录
您可以帮助我使用查询转换这些数据吗?
ID | DateTime | 状态 |
---|---|---|
1 | 2022-04-01 07:38:31 | 时间在 |
1 | 2022-04-01 12:07:17 | 中断 |
1 | 2022-04-01 12:07:39 | 突破 |
1 | 2022-04-01 16: 43:17 | 超时 |
1 | 2022-04-02 07:38:31 | 时间在 |
1 | 2022-04-02 12:07:39 | 突破 |
ID ID | 日期 | 日期时间 | 突破 | 超时 | 时间 |
---|---|---|---|---|---|
1 | 2022-04-01 | 07:38 :31 | 12:07:17 | 12:07:39 | 16:43:17 |
1 | 2022-04-02 | 07:38:31 | 12:07:39 | ||
1 | 2022-04-04-03 | ||||
1 | 2022-04-04-04 | ||||
1 | 2022-04--04--04-- 05 | ||||
1 | 2022-04-06 |
表日期应为2022-04-30。
Can you help me transform this data using query?
id | datetime | status |
---|---|---|
1 | 2022-04-01 07:38:31 | Time In |
1 | 2022-04-01 12:07:17 | Break In |
1 | 2022-04-01 12:07:39 | Break Out |
1 | 2022-04-01 16:43:17 | Time Out |
1 | 2022-04-02 07:38:31 | Time In |
1 | 2022-04-02 12:07:39 | Break Out |
id | date | Time In | Break In | Break Out | Time Out |
---|---|---|---|---|---|
1 | 2022-04-01 | 07:38:31 | 12:07:17 | 12:07:39 | 16:43:17 |
1 | 2022-04-02 | 07:38:31 | 12:07:39 | ||
1 | 2022-04-03 | ||||
1 | 2022-04-04 | ||||
1 | 2022-04-05 | ||||
1 | 2022-04-06 |
The table date should be up to 2022-04-30.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您需要使您使用的SQL类型使日期函数正确,这是T -SQL(MS SQL Server)代码:
A建议:考虑更改DateTime列的名称作为列的名称会在某个时候回来困扰您。
另外,如果您只需要时间部分,则将任何适合您的SQL风味的逻辑应用于DateTime中的任何逻辑。
You'll need to make the date function correct for the type of SQL you're using, this is T-SQL (MS SQL Server) code:
A suggestion: consider changing the name of the datetime column - giving a column a reserved word as a column name will come back to haunt you at some point.
Also, if you want just the time portion, then apply whatever logic is appropriate to your SQL flavor to parse that from the Datetime.