相交同一表的两列与列表/东西

发布于 2025-02-05 03:47:09 字数 1396 浏览 4 评论 0原文

以下结构的

ID相关过程
113271,13272,513008,51300913200,13271,19353,21101,21101,21105,21140
我在SQL Server中

创建了一个具有 to make an intersect between pertinent and procedure, and have the following result:

idpertinentprocedureprocedures pertinents
113271,13272,513008,51300913200,13271,19353,21101,21105,2114013271
21823618235,19290,19749,21102, 21105,21140null

,但我还没有弄清楚它如何迭代它或在SQL中划分它,有什么想法吗?先感谢您。

I created a table with the following structure in sql server:

idpertinentprocedure
113271,13272,513008,51300913200,13271,19353,21101,21105,21140
21823618235,19290,19749,21102,21105,21140

And I want to make an intersect between pertinent and procedure, and have the following result:

idpertinentprocedureprocedures pertinents
113271,13272,513008,51300913200,13271,19353,21101,21105,2114013271
21823618235,19290,19749,21102,21105,21140NULL

But i haven't figure it out how can i iterate it or split it in sql, any ideas? thank you in advance.

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

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

发布评论

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

评论(1

惯饮孤独 2025-02-12 03:47:10

第一步是将数据库标准化为1NF,每个元组具有一个值。然后,您将有两个表格,一个称为相关的表格,有5行,一个称为过程,有12行。之后,简单的选择语句与这些表之间的联接可以足够,从而产生所需的结果。

正如其他人提到的那样,在这个非常旧的SQL Server中,这将不必要地在此表上执行此操作。由于模式归一化可能是最好的,因此同时将数据库现代化可能是一个很好的电话。一些流行的选择将是Postgres和Snowflake,而我个人最喜欢的是Singlestore。

The first step would be to normalize the database to 1NF, having one value per tuple. Then you'd have two tables, one called pertinent, with 5 rows, and one called procedure, with 12 rows. After that, a simple SELECT statement with a JOIN between these tables would suffice, producing the desired results.

As others have mentioned, this would be unnecessarily hard to do on this table in this quite old version of SQL Server. Since a schema normalization is probably the best, modernizing the database at the same time might be a good call. Some popular choices would be Postgres and Snowflake, and my personal favorite is SingleStore.

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