2017-08-02 192 views

回答

0

一个简单的方法使用子查询在select

select (select column1, column2, column3, .... 
     from table1 
     where.... 
     ) as T1, 
     (select count(*) 
     from table2 
     where column1 = T1.column1 
     ) as T2; 
1

是的,我们可以作为一个美国总统曾经说过:

select table1.column1, count(*) 
from table1 
join table2 
on table1.column1 = table2.column1 
group by table1.column1 

会告诉你,你有多少元素在每个group。如果需要其他select值好,那么你将不得不由他们聚集中,通过将它们放入了group by条款或使用聚合函数对他们来说,就像group_concat把值放入您的分隔符分隔的列表。

相关问题