sql - 如何从 SQLite3 中的多个表中查询图像
问题描述
我有一个包含以下表格的 SQlite 图像数据库:
CREATE TABLE crowd_labels (mid int, attribute text, label text, primary key (mid, attribute));
CREATE TABLE modules (
mid int primary key,
project_id int,
src text
, mature_content, license);
CREATE TABLE scores (mid int,content_bicycle real, content_cat real, content_tree real, emotion_scary real, media_oilpaint real, content_bird real, content_dog real, emotion_gloomy real, media_3d_graphics real, media_pen_ink real, content_building real, content_flower real, emotion_happy real, media_comic real, media_vectorart real, content_cars real, content_people real, emotion_peaceful real, media_graphite real, media_watercolor real);
我可以单独执行以下查询,但我想知道如何将它们组合成一个查询:
sqlite3 mydatabase.sqlite <<EOF > cat_pictures.htm
select "<img src=""" || src || """ height=200>"
from modules, crowd_labels where modules.mid = crowd_labels.mid
and attribute = "content_cat"
and label="positive"
limit 100;
EOF
sqlite3 mydatabase.sqlite <<EOF > watercolor_pictures.htm
select "<img src=""" || src || """ height=200>"
from modules, scores where modules.mid = scores.mid
order by media_watercolor desc limit 0,100;
EOF
第一个查询将通过检查“crowd_labels”表返回一个包含 100 个猫图像的 html 文件,第二个查询将通过检查“scores”表返回一个包含 100 个水彩图像的 html 文件。
但是如果我想把两者结合起来,也就是把既是猫又是水彩的图像交集还给我,我该怎么做呢?
抱歉,如果这是一个非常简单的问题,但我在 SQL 方面的背景经验为 0。
解决方案
只需加入所有三个表:
SELECT '<img src="' || src || '" height=200>'
FROM modules
JOIN crowd_labels USING (mid)
JOIN scores USING (mid)
WHERE attribute = 'content_cat'
AND label = 'positive'
ORDER BY media_watercolor DESC
LIMIT 100;
推荐阅读
- rust - 内置测试器“定义”没有像我预期的那样工作
- haskell - 如何建立对 Servant 类型错误的直觉?
- oracle - 如何使用 Oracle XML DB Webservices 将表作为一行返回
- android - 从服务器获取数据后如何缓存数据?
- c# - 将文件分类到目录中
- r - Shiny 中的 Kmeans 实现
- wordpress - 如何使用 elementor 在 wordpress 中从头开始自定义页眉和页脚?
- android - “getDisplayLanguage()”总是返回“English”
- firebase-dynamic-links - 如何让我的 Firebase 动态链接重定向到我在桌面上的网站和我在移动设备上的即时应用
- python-3.x - 函数不能返回正确的值