如何根据三个条件检索记录?

How records can be retrieved based on three conditions?

我是 HQL 新手。我需要使用 HQL/SQL 查询根据以下 2 个条件从 table A 中获取所有记录: 满足这两个条件“(Music < 100) and (Dance != Normal)”(在 Table B 中)并且地点和国家是 A 和 AAA(在 Table C 中)的人员 ID。

Table以下:

[

[

[

如何根据这三个条件获取这些记录。谁能帮帮我。

输出应该是

在 Table A 中 ID 为 100 的记录,因为它的位置和值分别为 'A' 和 'AA'。而且它同时拥有音乐和舞蹈技能,音乐值大于100,舞蹈值不像'Normal'

select
*
from a 
inner join b as music on a.id = music.person_id and music.skills = 'Music'
inner join b as dance on a.id = dance.person_id and dance.skills = 'Dance'
inner join c on a.id = c.id 
where c.place = 'A' and c.country = 'AAA'
and music.score < '100'
and dance.score <> 'Normal'

尝试在文本而非数字的“score”列上使用 less than 时会遇到问题,请参阅下面的测试用例

CREATE TABLE mytable(
   Value VARCHAR(6) NOT NULL PRIMARY KEY
);
INSERT INTO mytable(Value) VALUES ('100');
INSERT INTO mytable(Value) VALUES ('a');
INSERT INTO mytable(Value) VALUES ('aa');
INSERT INTO mytable(Value) VALUES ('bbb');
INSERT INTO mytable(Value) VALUES ('cccc');
INSERT INTO mytable(Value) VALUES ('99');
INSERT INTO mytable(Value) VALUES ('9');
INSERT INTO mytable(Value) VALUES ('1');
INSERT INTO mytable(Value) VALUES ('19');
select
*
from mytable where value < '100'
| value |
| :---- |
| 1     |
select
*
from mytable where value > '100'
| value |
| :---- |
| a     |
| aa    |
| bbb   |
| cccc  |
| 99    |
| 9     |
| 19    |
select
*
from mytable where cast(value as integer) > 100
ERROR:  invalid input syntax for integer: "a"

db<>fiddle here