SQL-如何使用日期加入表格以获取所有日期的总体视图

发布于 2025-01-26 15:18:59 字数 199 浏览 2 评论 0原文

使用定制ERP系统与T&内置。 表1的日期为假期类型,即银行假期,用户预订的假期和用户ID。

表2具有该用户ID的所有时钟 - 因此,时间和日期,时钟,时间和日期,用户ID

可以在一周内显示所有日期,例如通过合并两个表。

例如,表1在星期一有银行假期,用户已经在周二,星期三,星期三,或者根本没有时钟,因为假日桌整个星期都放弃了它们?

Using a bespoke ERP system with T & A built in.
Table 1 has dates with holidays types i.e. bank holidays, user booked holidays - and a user id.

Table 2 has all the clockings for that user id - so, clock in time and date, clock out time and date, user id

Is there a way to show all of the dates in a week, for example by amalgamating the two tables.

E.g. table 1 has a bank holiday on monday, users have clocked tue, wed, thu - or a user hasn't clocked at all because the holiday table has them off all week?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2025-02-02 15:18:59

左JOIN 右JOIN 将解决问题。

SELECT T1.data1, T2.data2 FROM table1 AS T1
LEFT JOIN table2 AS T2
ON foreignKey1 = primnaryKey2

这将加入两个表,包括从“左”表中的空值。右连接对正确的连接也是如此。所有这些都取决于哪个表在外键中引用另一个表。请注意,在此示例中,T1剩下,T2是正确的。

A Left Join or Right Join would do the trick.

SELECT T1.data1, T2.data2 FROM table1 AS T1
LEFT JOIN table2 AS T2
ON foreignKey1 = primnaryKey2

This will join the two tables including the null values from the "left" table. Right joins do the same with the right one. All depends on which table references the other in a Foreign Key. Note that in this example T1 is left and T2 is right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文