我们用 select count(*) from t1 where....可以统计表中的记录数有没有这种办法,用一条查询语句同时统计多个不关联的表的记录,最好输出为一条数据,如:select count(t1.id) as total_1, count(t2.id) as total_2, count(t3.id) as total_3 from table1 as t1, table2 as t2, table3 as t3
join或union能实现吗,求解??????

解决方案 »

  1.   

    select (select count(id) from table1) as total_1,
    (select count(id) from table2) as total_2,
    (select count(id) from table3) as total_3;
      

  2.   

    select 'total_1' ,count(id) from table1
    union all
    select 'total_2' ,count(id) from table2
    union all
    select 'total_3' ,count(id) from table3
      

  3.   

    select count(t1.id) as total_1, count(t2.id) as total_2, count(t3.id) as total_3  
    from table1 as t1, table2 as t2, table3 as t3==》
    这样的显示形式 只能用子查询来代替显示了。。如下:
    select total_1=(select count(id) from table1),
    total_2=(select count(id) from table2),
    total_2=(select count(id) from table3)