t-sql:分页查询常见写法

本文介绍了三种SQL分页查询的方法,包括最佳方案、较好方案及最常见方案,并详细展示了每种方案的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SQL分页查询:

最佳方案:
SELECT TOP 10 *
FROM t_works
WHERE workId >
          (
          SELECT ISNULL(MAX(workId),0)
          FROM
                (
                SELECT TOP 59 workId FROM t_works ORDER BY workId
                ) t_works
          )
ORDER BY workId;

较好方案:
select top 10 *
FROM t_works
WHERE workId NOT IN
          (
          SELECT TOP 30 workId FROM t_works ORDER BY workId
          )
ORDER BY workId

最常见方案:
SELECT TOP 10 workId,enabled,state,parentId,warning,workType,sourceType,doWay,returnType,resultType,dept,operator,localTel,callTel,
 exCallTel,callName,address,regTime,waitTime,acceptTime,begTime,endTime,warnTime,finishTime,remark,soundFile,modTime
FROM
        (
        SELECT ROW_NUMBER() OVER (ORDER BY workId) AS RowNumber,* FROM t_works
        ) A
WHERE RowNumber > 10*(4-1);

<template> <view class="cd"> <image src="../../static/images/cd.png"></image> </view> <view class="out"> <custom-nav-bar-3 title="病例详情"></custom-nav-bar-3> <!-- 顶部装饰图片 --> <image class="logo" src="@/static/images/xinxing.png"></image> <!-- 搜索框 --> <view class="search"> <input v-model="name" type="text" placeholder="输入病例名或医生名搜索病例"> <u-icon @click="listBylike()" class="search-icon" name="search" size="10" width="167rpx" height="30rpx"></u-icon> </view> <!-- 主要内容区域 --> <view class="content-container"> <!-- 病例列表 --> <view class="content"> <view class="content-item" v-for="item in diseaseList" :key="item.id" @click="goToDetails(item.id)"> <!-- 标签 --> <view class="tag"> <u-icon name="integral-fill" color="orange" size="12"></u-icon> <text>{{item.type == 0 ? '免费病例' : item.type == 1 ? '会员免费' : '付费病例'}}</text> </view> <!-- 封面图片 --> <view class="cover"> <image class="cover-image" v-if="item.pic && item.pic.length > 0" :src="'http://111.32.131.98:3336/ ' + item.pic[0]" mode="aspectFit" lazy-load></image> <image class="cover-image" v-else src="../../static/images/noPic.png" mode="aspectFit"></image> </view> <!-- 病例信息 --> <view class="info"> <view class="title"> {{item.name}} </view> <view class="detail"> <text>浏览量 <text style="font-weight: 400; color: rgba(35, 186, 176, 1); font-size: 9rpx;">{{item.browse ? item.browse : 0}}次</text></text> <text>累计购买 <text style="font-weight: 400; color: rgba(35, 186, 176, 1); font-size: 9rpx;">{{item.count ? item.count : 0}}次</text></text> </view> <view class="item-bottom"> <view class="left"> <view class="avatar"> <image src="@/static/images/touxiang1.png" mode="aspectFill"></image> </view> <text style="margin-left: 7rpx; font-size: 9rpx;">{{item.doctorName ? item.doctorName : '佚名'}}</text> </view> <view class="price" :style="{ color: (item.type === 0 || item.type === 1) ? '#5078F8' : '#FF1C1C'}"> {{item.type == 0 ? '免费病例' : item.type == 1 ? '会员免费' : '¥' + item.price}} </view> </view> </view> </view> </view> </view> </view> </template> <script setup> import { ref, onMounted } from 'vue'; import { dListByNameService, getCategoryListService, listByCategoryIdService } from '../../api'; // 数据 const name = ref(''); const diseaseList = ref([]); const categorys = ref([]); const show = ref(false); // 模糊查询病例 const listBylike = async () => { try { let result = await dListByNameService(name.value); // 处理图片数据 result.data.forEach(item => { if (item.pic) { item.pic = item.pic.split(','); } else { item.pic = []; } }); diseaseList.value = result.data; console.log("模糊查询API返回值:", result.data); } catch (error) { console.error("调用 API 时出错:", error); } }; // 页面加载时自动执行一次查询 onMounted(() => { listBylike(); }); // 获取病例分类列表 const getCategoryList = async () => { try { let result = await getCategoryListService(); categorys.value = result.data.map(item => ({ value: item.id, label: item.name })); } catch (error) { console.error("获取分类列表出错:", error); } }; // 获取分类列表 getCategoryList(); // 选中分类后重新查询 const confirm = async (e) => { try { let category = e[0]; let result = await listByCategoryIdService(category.value); // 处理图片数据 result.data.forEach(item => { if (item.pic) { item.pic = item.pic.split(','); } else { item.pic = []; } }); diseaseList.value = result.data; console.log('通过分类查询', diseaseList.value); } catch (error) { console.error("分类查询出错:", error); } }; // 打开分类选择窗口 const showSelect = () => { show.value = true; }; // 跳转到病例详情页面 const goToDetails = (id) => { uni.navigateTo({ url: '/pages/disease-info/disease-info?id=' + id }); }; </script> <style lang="scss"> * { margin: 0; padding: 0; box-sizing: border-box; } .cd image{ position:absolute; width: 20rpx; height: 15rpx; top:39rpx; left:700rpx; z-index: 1; } .out { height: 100vh; background: linear-gradient(180deg, rgba(34, 185, 176, 1) 0%, rgba(250, 250, 250, 1) 35.2%, rgba(246, 247, 248, 1) 100%); position: relative; overflow: hidden; padding: 0 32rpx; overflow-y: auto; /* 添加此行 */ } .logo { position: absolute; left: 444rpx; top: -50rpx; width: 254rpx; height: 234rpx; z-index: 1; } .content-container { position: relative; padding-top: 160rpx; top: -150rpx; z-index: 2; } .category { position: fixed; top: 380rpx; right: 32rpx; background-color: #ff9800; border-radius: 50%; width: 80rpx; height: 80rpx; text-align: center; line-height: 80rpx; color: #FFFFFF; font-size: 28rpx; z-index: 99; } .search { position: relative; margin-bottom: 40rpx; z-index: 10; } .search input { width: 170rpx; height: 35rpx; background: #FFFFFF; border-radius: 42rpx; border: 1rpx solid #e8e5e3; font-size: 9.8rpx; padding-left: 5rpx; position: absolute; right: 30rpx; top: 25rpx; } .search-icon { position: absolute; right: 10%; top: 37rpx; right: 40rpx; width: 13rpx; height: 13rpx; z-index: 10; } .content { display: flex; flex-wrap: wrap; justify-content: space-between; width: 100%; padding-top: 40rpx; } .content-item { padding: 15rpx; box-sizing: border-box; display: flex; align-items: center; width: calc(50% - 10rpx); /* 每列占据50%的宽度,减去间距的一半 */ height: 97rpx; background: rgba(255, 255, 255, 1); border-radius: 7rpx; position: relative; margin-bottom: 7rpx; overflow: hidden; } .tag { position: absolute; top: 0; right: 0; text-align: center; width: 63rpx; height: 17rpx; background: linear-gradient(180deg, #FEE8C9 0%, #FFD497 100%); border-radius: 0rpx 10rpx 0rpx 10rpx; display: flex; align-items: center; justify-content: center; z-index: 2; } .tag text { font-weight: 500; font-size: 9rpx; color: #876B43; margin-left: 7rpx; } .cover { width: 200rpx; height: 180rpx; display: flex; justify-content: center; align-items: center; overflow: hidden; /* 超出部分隐藏 */ } .cover-image { max-width: 100%; max-height: 100%; object-fit: cover; /* 关键属性:保持比例并填充容器 */ border-radius: 8rpx; } .info { margin-left: 7rpx; width: calc(100% - 170rpx); padding-right: 7rpx; } .title { margin-top: 17rpx; font-family: Source Han Sans CN; font-weight: 500; font-size: 10rpx; color: #333333; } .detail { margin: 10rpx 0 15rpx 0; display: flex; justify-content: space-between; font-family: Source Han Sans CN; } .detail text { font-weight: 400; font-size: 9rpx; color: #666666; } .item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: -10rpx; } .left { display: flex; align-items: center; font-size: 9rpx; font-weight: 400; line-height: 25rpx; color: rgba(102, 102, 102, 1); } .avatar { width: 17rpx; height: 17rpx; background: #FFFFFF; border-radius: 50%; overflow: hidden; margin-right: 7rpx; } .avatar image { border-radius: 50%; width: 100%; height: 100%; } .price { font-family: Source Han Sans CN; font-weight: 500; font-size: 12.6rpx; font-style: normal; text-transform: none; line-height: 16px; } </style>给这段代码加分页查询功能调用接口为 //分页查询,通过医生名字,病例名模糊查询病例信息 export const dListByNameService = (name,pageSize=10,pageNum=1) => { return request({ url: '/disease/listByName', data: { name, pageSize, pageNum, } }) }
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值