[英]Search SQL request with two tables on PostgreSQL. SQLAlchemy. Python
Need help in request making on SQL or SQLAlchemy在 SQL 或 SQLAlchemy 上提出请求时需要帮助
First table named as Rows第一个表名为Rows
sid![]() |
unit_sid![]() |
---|---|
ROW_UUID1 ![]() |
UNIT_UUID1 ![]() |
ROW_UUID2 ![]() |
UNIT_UUID1 ![]() |
ROW_UUID3 ![]() |
UNIT_UUID ![]() |
Second table with name Records名称为Records的第二个表
row_sid (==SID from ROWS) ![]() |
item_sid ![]() |
content (str)![]() |
---|---|---|
ROW_UUID1 ![]() |
ITEM_UUID1 ![]() |
Decription 1![]() |
ROW_UUID1 ![]() |
ITEM_UUID2 ![]() |
Decription 1![]() |
ROW_UUID2 ![]() |
ITEM_UUID1 ![]() |
Description 3![]() |
ROW_UUID2 ![]() |
ITEM_UUID2 ![]() |
Description 2![]() |
ROW_UUID3 ![]() |
ITEM_UUID1 ![]() |
Description 5![]() |
ROW_UUID3 ![]() |
ITEM_UUID2 ![]() |
Description 1![]() |
I need an example of a SQL query, where I can specify a search for several content values for different item_sid我需要一个 SQL 查询的示例,我可以在其中指定搜索不同 item_sid 的多个内容值
For example I need all ROWS where例如我需要所有行
Request like bellow will not work for me, because I need search in two item_sid in same time for receiving unique ROWS像下面这样的请求对我不起作用,因为我需要同时搜索两个 item_sid 以接收唯一的 ROWS
select row_sid
from rows
left join record on rows.sid = record.row_sid
where (item_sid = '877aeeb4-c68e-4942-b259-288e7aa3c04b' and
content like '%TEXT%')
and (item_sid = 'cc22f239-db6c-4041-92c6-8705cb621525' and
content like '%TEXT2%') GROUP BY row_sid
Solved like解决像
select row_sid
from rows
left join record on rows.sid = record.row_sid
where (item_sid = '877aeeb4-c68e-4942-b259-288e7aa3c04b' and
content like '%TEXT%')
or (item_sid = 'cc22f239-db6c-4041-92c6-8705cb621525' and
content like '%TEXT2%') GROUP BY row_sid having count(row_sid) = 2
But maybe there are more beautiful solution?但也许有更漂亮的解决方案? I want to request different number of item_sids (2-5) in the same time
我想同时请求不同数量的 item_sids (2-5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.