【发布时间】:2019-04-07 21:48:41
【问题描述】:
我正在创建一个基本的 ASP.net 博客主页。 我有两个表(结构如下)。我需要这些表中的数据进行分页,所以我在查询本身中使用了 offset 和 skip。
这些表格是:
表格 - 博客:
Id(primary),
Description,
Data,
CreatedById,
CreatedDate,
ImageUrl,
IsDeleted,
Tags,
StatusId(value = 1 for draft and 2 for publish)
表格 - BlogCategories:
Id,
BlogId(foreign key to table 1),
CategoryId
这些表中已有数据。我正在使用以下查询来获取数据
Select *
from Blog b inner join
BlogCategories bc
on b.Id = bc.BlogId
where b.StatusId = 2 and bc.CategoryId = 2 and b.IsDeleted = 0
ORDER BY b.CreatedDate desc
OFFSET 73 ROWS
FETCH NEXT 9 ROWS ONLY;
此查询返回 0 行,但如果我从 where 子句中删除 statusId 和 CategoryId,查询将返回一定数量的行。
预期结果是:
我做错了什么还是有更好的方法。请帮我解决一下这个。谢谢你。
【问题讨论】:
-
请输入数据和预期结果
-
返回什么:
Select count(*) from Blog b inner join BlogCategories bc on b.Id = bc.BlogId where b.StatusId = 2 and bc.CategoryId = 2 and b.IsDeleted = 0 -
@AntonínLejsek 在我的数据库中返回计数 7
标签: c# mysql sql asp.net pagination