SQL 中连接和更新表的方法

发布于 2024-09-13 22:21:54 字数 612 浏览 1 评论 0原文

所以我是这里的第一次用户,并且对 SQL 还比较陌生。我正在尝试拿两张桌子,并在某种意义上将它们连接起来。

在表 1 中,我有数据:

House_Key ---Other Fields---   Customer_ID

House_Key 不是唯一的,因此每个家庭可以有多个 Customer_ID。 House_Key 是数字代码,Customer_ID 是 Home、Business 或 Bulk。

在表 2 中,我有 House_Key 字段,但没有 Customer_ID 字段。

我的目标是创建一个新表,其中包含 Table2 的字段,其中包含一个名为 Customer_ID 的字段,但我不想像表 1 那样为每种类型的 Customer_ID 建立一个新行,而是希望每个 House_Key 只有一行,并且如果是全部三个或任意组合,Customer_ID 会显示类似“Home Business Bulk”的内容,但希望字段中始终将“Home”放在“Business”之前,然后将“Bulk”放在“Bulk”之前。

有什么办法可以做到这一点吗?提前非常感谢您。

另外,不确定这是否重要,但如果确实如此,我正在使用 SQL Server 2005。

So I am a first time user here, and still relatively new to SQL. I am attempting to take 2 tables, and join them in a sense.

In Table1 I have the data:

House_Key ---Other Fields---   Customer_ID

House_Key is not unique, and as such I can have multiple Customer_IDs per household. House_Key is a numerical code, and Customer_ID is either Home, Business, or Bulk.

In Table2 I have the House_Key field, but not the Customer_ID field.

My goal is to have a new table that holds the fields of Table2 with a field called Customer_ID, but instead of having a new row for each type of Customer_ID like in Table 1, I want to have each House_Key only have one row, and the Customer_ID say something like "Home Business Bulk" if it is all three or any combination of them, but would prefer that it always have Home before Business before Bulk in the field.

Is there any way to do this? Thank you very much ahead of time.

Also, not sure if it matters, but in case it does I'm using SQL Server 2005.

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

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

发布评论

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

评论(1

踏雪无痕 2024-09-20 22:21:54

哇,我很高兴您来这里寻求答案,但似乎您确实需要阅读一些有关关系数据库的内容。

这里不写冗长的答案,而是链接:

http://en.wikipedia.org/wiki/Database_normalization

http://en.wikipedia.org/wiki/Join_(SQL)< /a>

Wow, I'm glad that you came here for an answer, but seems that you really need some reading about relational databases.

Instead of writing looong answer here're the links:

http://en.wikipedia.org/wiki/Database_normalization

http://en.wikipedia.org/wiki/Join_(SQL)

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