我想构建这样的查询 - >
select table1.colname,(select count(*) from table1.colname) As count from table1;
在mysql中可以吗?
请帮帮我..
答案 0 :(得分:0)
您可以尝试使用Stored Procedure,类似这样的内容:
CREATE PROCEDURE test_procedure()
READS SQL DATA
BEGIN
declare table_name varchar(50);
DECLARE cur_input CURSOR FOR select table1.colname from table1;
OPEN cur_input;
loop1:loop FETCH cur_input INTO table_name;
select table_name,(select count(*) from table_name) As count from table1;
END loop loop1;
END;