我是新手在mysql中查询表并使用存储过程。我在下面有这个查询,我想查询>5
的所有数据。是否存在类似select * from table Except top 5
之类的查询,因此它将从数据#6
开始我搜索一些代码,但我发现只是一个没有条件的直接查询。
SELECT *
FROM dbo.PersonSkill INNER JOIN
dbo.SpecialSkill ON dbo.PersonSkill.SpecialSkillsId = dbo.SpecialSkill.SpecialSkillsId
WHERE dbo.PersonSkill.PersonId = @PersonId
答案 0 :(得分:2)
您可以简单地使用LIMIT参数。
LIMIT 5, 10
第一个参数(5) - 从
开始第二个参数(10) - 要选择的行数
答案 1 :(得分:2)
试试这个
SELECT *
FROM dbo.PersonSkill INNER JOIN
dbo.SpecialSkill ON dbo.PersonSkill.SpecialSkillsId = dbo.SpecialSkill.SpecialSkillsId
WHERE dbo.PersonSkill.PersonId = @PersonId and unique_id not in (SELECT top 5 unique_id
FROM dbo.PersonSkill INNER JOIN
dbo.SpecialSkill ON dbo.PersonSkill.SpecialSkillsId = dbo.SpecialSkill.SpecialSkillsId
WHERE dbo.PersonSkill.PersonId = @PersonId )
答案 2 :(得分:2)
SQL Server没有LIMIT或OFFSET函数,但您可以像this一样模拟此行为,结果如下:
;WITH Results_CTE AS
(
SELECT
dbo.PersonSkill.*, dbo.SpecialSkill.SpecialSkillsId, dbo.SpecialSkill.OtherCol
ROW_NUMBER() OVER (ORDER BY @PersonId) AS 'RowNum'
FROM dbo.PersonSkill
INNER JOIN dbo.SpecialSkill
ON dbo.PersonSkill.SpecialSkillsId = dbo.SpecialSkill.SpecialSkillsId
WHERE dbo.PersonSkill.PersonId = @PersonId
)
SELECT *
FROM Results_CTE
WHERE RowNum >5
答案 3 :(得分:1)
试试这个
SELECT * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY @PersonId) as rn
FROM dbo.PersonSkill INNER JOIN
dbo.SpecialSkill ON dbo.PersonSkill.SpecialSkillsId = dbo.SpecialSkill.SpecialSkillsId
WHERE dbo.PersonSkill.PersonId = @PersonId)A where A.rn>5