惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
WordPress大学
WordPress大学
B
Blog RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
MyScale Blog
MyScale Blog
GbyAI
GbyAI
Martin Fowler
Martin Fowler
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
The Cloudflare Blog
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
Google DeepMind News
Google DeepMind News
S
Securelist
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
Latest news
Latest news
T
Threatpost
量子位
Y
Y Combinator Blog
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
博客园_首页
AWS News Blog
AWS News Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
宝玉的分享
宝玉的分享
Project Zero
Project Zero
V
Visual Studio Blog
F
Fortinet All Blogs
S
Security Affairs
The Register - Security
The Register - Security
G
Google Developers Blog
T
Tenable Blog
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
博客园 - Franky

博客园 - Kevin

换工作了,记录一下面试情况 打工的就是打工的! 超强的希捷硬盘 在一个表里添加了一记录,怎样取得这条记录的id 发布程序到远程服务器 DNN所有表结构 web.config信息及RSA加密方式! vs2005调用js脚本方法总结 Using JavaScript to show the current time for the end user HtmlGenericControl操作meta标记 window2k3集成sp1光盘启动工具版 CodeSmith资源 华硕网站ajax应用分析-js脚本 Ajax程序设计入门 SQL Server端口更改后的数据库连接方式 windows2003server自带防火墙导致sql server2k无法访问,谁有好办法? 局域网访问access数据库 dreamweaver+asp+access+vss不该犯的错误 windows2k3server远程桌面连接,”终端服务器超出了最大允许连接数“的解决办法
如何一次性取出每个类别下的前n条记录
Kevin · 2006-03-14 · via 博客园 - Kevin

两张表:
    Tongs
TongId    int
Title     nvarchar(50)
TypeId    int

    TongType
TypeId    int
TypeName  nvarchar(20)


取出某一类别下前n条记录可用:
select top n TongId,Title from Tongs where TypeId = @TypeId

但我希望一次取出所有类别里的前n条记录
不用存储过程

我自己想到的一个解决办法是:
在Tongs表中置一标识位
    Tongs
TongId    int
Title     nvarchar(50)
TypeId    int
IsShow    bool

select top n TongId,Title from Tongs where IsShow=1 order by TypeId,TongId desc

在插入新记录时,我把插入前当前类别下通过上面的select语句选出的第n条语句的IsShow置0

参考:

http://community.csdn.net/Expert/topic/4234/4234286.xml?temp=.5002558

高手的方法

select
    a.*
from
    Tongs a
where
    a.TongId in(select top N TongId from Tongs where TypeId=a.TypeId order by TongId desc)