数据准备:
CREATE TABLE `subject` (
`ID` int NOT NULL,
`CLASSID` int DEFAULT NULL,
`SUBJECTNAME` varchar(20) DEFAULT NULL,
`score` float(5,2) DEFAULT NULL,
`GARDEID` int DEFAULT NULL
)
INSERT INTO subject
(ID, CLASSID, SUBJECTNAME, score, GARDEID)
VALUES(1, 8, 'java', 81.9, 56);
INSERT INTO subject
(ID, CLASSID, SUBJECTNAME, score, GARDEID)
VALUES(2, 11, 'java', 117.24, 49);
sql实现动态查询
set @select = ' select * from ';
set @table = 'subject s';
set @where = ' limit 2';
set @sqls = concat(@select, @table,@where);
PREPARE stmt FROM @sqls;
EXECUTE stmt ;
|