例子:
id name agreement
32 fahid 52
43 nahid 51
31 zal 52
想通过协议选择,但我想保留给定的顶部id
,如果我使用,order by
那么总是对 id 进行排序。如果我搜索agreement=52
然后id=32
预期结果:
32 fahid 52
31 fahid 52
例子:
id name agreement
32 fahid 52
43 nahid 51
31 zal 52
想通过协议选择,但我想保留给定的顶部id
,如果我使用,order by
那么总是对 id 进行排序。如果我搜索agreement=52
然后id=32
预期结果:
32 fahid 52
31 fahid 52
尝试这个
DECLARE @id INT
DECLARE @agreement INT
SET @id = 32
SET @agreement = 52
SELECT [id]
, (SELECT [name] FROM Table1 WHERE [id] = @id) AS [name]
, [agreement] FROM Table1
WHERE [agreement] = @agreement
输出
id name agreement
32 fahid 52
31 fahid 52
您可以按顺序使用多个字段
order by id,agreement
在 mysql 中使用 LIMIT
MySQL 语法
SELECT column_name(s)FROM table_name WHERE (condition) LIMIT number;
例子
SELECT * FROM Persons WHERE agreement=52 LIMIT 5;
甲骨文语法
SELECT column_name(s)FROM table_name WHERE ROWNUM <= number;
例子
SELECT * FROM Persons WHERE ROWNUM <=5;