如何加入两个 table 以多次扩展某行
How to join two table to expand certain row multiple times
table 1
Places Type
All Places Food
All Places Dessert
...
table 2
Places Weather
JH Cloudy
Martin Sunny
Jones Rainy
Brownsville Sunny
Nashville Sunny
如何获取 table 2
列 Places
并将其与 table 1
合并
我希望 table 1
成为(示例:扩展 All Places
使 table 2
中的每个地方都具有 Food
类型:
Places Type
JH Food
Martin Food
Jones Food
Brownsville Food
Nashville Food
JH Dessert
Martin Dessert
Jones Dessert
Brownsville Dessert
Nashville Dessert
...
我正在使用 MS Sql 服务器 2012。
更新:
table 1
Specialty Topic
Infectious Disease Not Satisfied
Pediatrics Advice / Triage
All Specialties After Hours
All Specialties Age Restrictions
OBGYN Alpha- Feto Protein
table 2
Specialty Version
All Specialties All Specialties
OBGYN 2.0
Pediatrics 1.1
Infectious Disease 0.9
table 1
应该更新为:
Specialty Topic
Infectious Disease Not Satisfied
Pediatrics Advice / Triage
OBGYN After Hours
Pediatrics After Hours
Infectious Disease After Hours
OBGYN Age Restrictions
Pediatrics Age Restrictions
Infectious Disease Age Restrictions
OBGYN Alpha- Feto Protein
可能是 Cartesian product
SELECT b.places,
a.type
FROM table1 a
CROSS JOIN table2 b
WHERE a.places = 'All Places'
更新:
SELECT b.places,
a.type
FROM table1 a
CROSS JOIN table2 b
WHERE a.places = 'All Places'
union
select places,type from
table1
where places <> 'All Places'
table 1
Places Type
All Places Food
All Places Dessert
...
table 2
Places Weather
JH Cloudy
Martin Sunny
Jones Rainy
Brownsville Sunny
Nashville Sunny
如何获取 table 2
列 Places
并将其与 table 1
我希望 table 1
成为(示例:扩展 All Places
使 table 2
中的每个地方都具有 Food
类型:
Places Type
JH Food
Martin Food
Jones Food
Brownsville Food
Nashville Food
JH Dessert
Martin Dessert
Jones Dessert
Brownsville Dessert
Nashville Dessert
...
我正在使用 MS Sql 服务器 2012。
更新:
table 1
Specialty Topic
Infectious Disease Not Satisfied
Pediatrics Advice / Triage
All Specialties After Hours
All Specialties Age Restrictions
OBGYN Alpha- Feto Protein
table 2
Specialty Version
All Specialties All Specialties
OBGYN 2.0
Pediatrics 1.1
Infectious Disease 0.9
table 1
应该更新为:
Specialty Topic
Infectious Disease Not Satisfied
Pediatrics Advice / Triage
OBGYN After Hours
Pediatrics After Hours
Infectious Disease After Hours
OBGYN Age Restrictions
Pediatrics Age Restrictions
Infectious Disease Age Restrictions
OBGYN Alpha- Feto Protein
可能是 Cartesian product
SELECT b.places,
a.type
FROM table1 a
CROSS JOIN table2 b
WHERE a.places = 'All Places'
更新:
SELECT b.places,
a.type
FROM table1 a
CROSS JOIN table2 b
WHERE a.places = 'All Places'
union
select places,type from
table1
where places <> 'All Places'