如何通过利用子查询将这两个查询转换为一个查询?
select p.id, m.display_name, m.updated_at, group_concat(meta.value) as value, p.path
from metadata_custom meta
right join page as p on p.id = meta.page_id
inner join metadata m on p.metadata_id = m.id
where p.path like '/history/%' and p.path not like '/history/%/%'
group by p.id
SELECT * FROM cascade_publish.folder
where path like '/history/%' and path not like '/history/%/%'
我见过的大多数子查询都使用WHERE IN .... 我最好能够将第二个查询放在第一个查询的某个地方,我该怎么做呢?
答案 0 :(得分:0)
一种方法是使用子查询作为选择字段:
SELECT p.id
( SELECT folder FROM cascade_publish
where path like '/history/%' and path not like '/history/%/%') as publish_folder
FROM ...
答案 1 :(得分:0)
您可以在表格通常位置的任何位置添加带有别名的SELECT
。例如:
SELECT * FROM table
JOIN (SELECT * FROM other_table WHERE x = 10) AS temp
或者,像这样:
SELECT SUM(temp.value) FROM (SELECT MAX(value) AS value FROM my_table GROUP BY whatever) AS temp