简体   繁体   English

SQL连接两个没有键/关系的表

[英]SQL join two tables without keys/relations

I have two tables, one of them has weeks of year, and the second table has categories. 我有两张桌子,其中一张桌子有一周,而第二张桌子有几个类别。 I need to create a table that contains each week and each category, but there's no fields/keys that intersect in two tables: 我需要创建一个包含每周和每个类别的表,但是没有字段/键在两个表中相交:

Table 1: 表格1:

week1
week2
week3
week4

Table 2: 表2:

Cat1
Cat2

Resulting table: 结果表:

week1 cat1
week1 cat2
week2 cat1
week2 cat2
...
week4 cat1
week4 cat2

I'd like to do this without using many cursors/looping. 我想在不使用许多游标/循环的情况下执行此操作。

SELECT * FROM Table1 CROSS JOIN Table2

这将为您提供Table1和Table2中所有列的每个组合。

你尝试过吗?

 SELECT * FROM table1, table2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM