求个SQL语句
表数据如下:
ID NUM
---------------------
1 10
2 -50
3 -100
4 30
5 50
6 60
7 -200
8 70
9 200
10 80
……
字段NUM的数据,有正有负,记录是会增加的。
我想取出最后一次出现 NUM为负数的ID
不知SQL该如何写?
SQL code:
select top id from tb where num<0 order by id desc
select top 1 id from tb
where num <0
order by id
select top 1 id from tb
where num <0
order by id desc
楼上的好快啊
SQL code:
select top 1 id
from tb
where num<0
order by id desc
SQL code
Code highlighting produced by Actipro CodeHighlighter (freew
相关问答:
场景如下:
客户把备份好的数据库,发给我,我在本机还原后,运行写好的存储过程,比较快,并且在实施那边运行同样比较快。但是当实施在客户那边运行的时候速度就非常的慢,时间超出了程序的时间限制。远程在客户那 ......
--drop table #T1
--drop table #T2
create Table #T1(ID int,
QueryID nvarchar(20),
ResultID1 nvarchar(20),
ResultID2 nvarchar(20))
create Table #T2(SortNo int,
QueryID nvarchar(20),
ResultID1 nv ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......