CREATE TEMP TABLE var(name VARCHAR(255),integer INT(5),string VARCHAR(255)); -- my variables
CREATE TEMP TABLE param(name VARCHAR(255),integer INT(5),string VARCHAR(255)); -- my parameters
INSERT INTO param (name,string) VALUES('search',''); -- assigning my parameters
INSERT INTO param (name,string) VALUES('page',1);
INSERT INTO param (name,integer) VALUES('rows',10);
INSERT INTO var (name,integer) VALUES('initindex',( (SELECT integer FROM param WHERE name='page') - 1 ) * (SELECT integer FROM param WHERE name='rows')); --calculating my variable using the parameters
SELECT CASE (SELECT string FROM param WHERE name='search') -- querying
WHEN '' THEN (SELECT * FROM clients ORDER BY id ASC LIMIT 10 OFFSET (SELECT integer FROM var WHERE name='initindex'))
ELSE
(SELECT * FROM clients
WHERE id LIKE '%'||(SELECT string FROM param WHERE name='search')||'%'
OR name LIKE '%'||(SELECT string FROM param WHERE name='search')||'%'
OR first_date= (SELECT string FROM param WHERE name='search')
OR last_date= (SELECT string FROM param WHERE name='search')
OR pass LIKE '%'||(SELECT string FROM param WHERE name='search')||'%'
ORDER BY id ASC LIMIT (SELECT integer FROM param WHERE name='rows') OFFSET (SELECT integer FROM var WHERE name ='initindex'))
END
FROM clients;
DROP TABLE var;
DROP TABLE param;
当我执行整个查询时,我收到一个错误:
[19:07:08]在数据库'DataBase'上执行SQL查询时出错:只有一个结果允许作为表达式一部分的SELECT
此外,当我执行每个子查询时,它只会产生一个唯一的行。
因为表var
和param
(模拟为MySQL语法中的变量和参数)总是只返回一个值。