我们使用最新的mysql-connector-java
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
我正在使用JDBI进行联合查询,其中每个选择的某些列中的区域为空。
简而言之,
SELECT a.a, s.b, null as c
from settings s
inner join area a
on area.id = s.area
UNION ALL
SELECT a.a, null as b, o.c
from other_settings o
inner join area a
on area.id = s.area
但是当第2列中有247个未知数据类型时,SQL语句将无法执行。如果我将null更改为字符串,并且对于该字符串,它可以作为一种变通方法,但这似乎很麻烦。
CREATE TABLE area (int id, a varchar(64), primary key(id));
CREATE TABLE settings (int id, int area, b varchar(64), primary key(id), CONSTRAINT fk_setting_area FOREIGN KEY(area) REFERENCES area(id));
CREATE TABLE other_setting (int id, int area, c varchar(64) primary key(id), CONSTRAINT fk_other_rea FOREIGN KEY(area) REFERENCES area(id);