I don't know how to create a stored procedure and using select in while statement. This query will come to this error "unknown system variable 'tableview'". Anyone help me please to repair it. Thanks for your helping.
CREATE PROCEDURE tablebts()
BEGIN
DECLARE x INT;
SET x=0;
SET tableview;
WHILE x < 10 DO
SET x=x + 1;
SET tableview = SELECT idbts
FROM (SELECT idbts, namesite, COUNT(idbts) AS jumlah
FROM (SELECT ts.site_id AS idbts, tps.msisdn AS msisdn, tb.site_name AS namesite
FROM tb_profile_subscribers tps
INNER JOIN tb_sitemap ts
ON tps.lac=ts.lac2g
or tps.lac=ts.lac3g
AND tps.cellid=ts.ci2g
OR tps.cellid=ts.ci3g_850
OR tps.cellid=ts.ci3g_2100_1
OR tps.cellid=ts.ci3g_2100_2
OR tps.cellid=ts.ci3g_2100_3
INNER JOIN tb_bts tb
ON ts.site_id=tb.site_id
GROUP BY msisdn) msisdn
GROUP BY idbts
ORDER BY jumlah DESC
LIMIT 1 OFFSET x) AS tabelbts
END WHILE;
SELECT tableview;
END$$
I also put x variable in tableview query (the word "offset x"). Is that true? Help me please and thanks in advance