0
有两个查询如下:加入两个选择查询,其中一个查询的结果是依赖于另一个查询
select column1, column2, column3, ....
from table1
where.... as T1
select count(*)
from table2
where column1 = T1.column1
是否有可能两者结合成一个查询
有两个查询如下:加入两个选择查询,其中一个查询的结果是依赖于另一个查询
select column1, column2, column3, ....
from table1
where.... as T1
select count(*)
from table2
where column1 = T1.column1
是否有可能两者结合成一个查询
一个简单的方法使用子查询在select
:
select (select column1, column2, column3, ....
from table1
where....
) as T1,
(select count(*)
from table2
where column1 = T1.column1
) as T2;
是的,我们可以作为一个美国总统曾经说过:
select table1.column1, count(*)
from table1
join table2
on table1.column1 = table2.column1
group by table1.column1
会告诉你,你有多少元素在每个group
。如果需要其他select
值好,那么你将不得不由他们聚集中,通过将它们放入了group by
条款或使用聚合函数对他们来说,就像group_concat
把值放入您的分隔符分隔的列表。