1
我想建立這樣的查詢 - >我可以使用一個表列值作爲mysql中的另一個表表名嗎?
select table1.colname,(select count(*) from table1.colname) As count from table1;
是否有可能在MySQL?
請幫助我..
我想建立這樣的查詢 - >我可以使用一個表列值作爲mysql中的另一個表表名嗎?
select table1.colname,(select count(*) from table1.colname) As count from table1;
是否有可能在MySQL?
請幫助我..
你可以嘗試使用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;
你爲什麼不嘗試一下? – Jens
我已經嘗試,但我越來越table1.colname是不存在..錯誤 –
你的查詢語法看起來不錯,檢查如果存在'table1'表中的'colname'列如果你得到這個錯誤 – lubilis