我有张表:user 列:id,charm,name 其中charm 是int型,存储魅力值的,现在假如id= 123的用户的charm值= 432 ,求id=123的用户根据charm排序后,该用户是排行第几?这个在数据中怎么弄啊
解决方案 »
- a,b两个表,我要求A表增加记录B表也增加,A表删除记录B表也删除同样记录,如何用触发器实现?
- 一条面试的SQl没写出来,面试黄了
- 求一高难度实战型SQL语句,涉及父子关系。在线急等!!!50分!!高手进!!
- 遇到奇怪问题
- 新手提问数据库操作问题。
- sql远程服务器导入我本地的数据,为什么没有把存储过程导入进去呢,那怎么弄? 还原可以把储存过程弄进去吗,但是我没有权限啊。
- 数据导入导出
- 如何查看被加密的存储过程-在线等待
- 急,在线给分,如何用最好的方法将多个表中的记录追加到一个表中去?这些表结构完全一样
- 由SYBASE 转学ORACLE,请各位师兄推荐好书,以便我能迅速掌握ORACLE,这可是我的饭碗啊,衷心地感谢!!!
- 数据批量添加验证
- 有点怪异的 SQL Servier 2000 这样的SQL语句查询不出记录
排名=(select count(*) from [user] where charm>t.charm)
from [user] t
select *,(select count(*) from tb b where a.charm<=b.charm) as rn
from tb a) a
where a.id=123
select *,(select count(distinct b.charm) from tb b where a.charm<=b.charm) as rn
from tb a) a
where a.id=123可以求并列的
select
*,
排名=row_number()over(partition by id order by charm),*
from
tb
where
id=123
if object_id('[TB]') is not null drop table [TB]
create table [TB]([id] int,[point] int,[name] varchar(4))
insert [TB]
select 1,100,'张三' union all
select 2,80,'李四' union all
select 3,80,'王五' union all
select 4,75,'杨六' union all
select 5,75,'方七'select id=(select count([point])+1 from TB where T.[point]<[point]),point,name
from TB t/*
id point name
----------- ----------- ----
1 100 张三
2 80 李四
2 80 王五
4 75 杨六
4 75 方七(5 行受影响)
*/drop table TB--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([id] int,[point] int,[name] Nvarchar(4))
insert [TB]
select 1,100,N'张三' union all
select 2,80,N'李四' union all
select 3,80,N'王五' union all
select 4,75,N'杨六' union all
select 5,75,N'方七'select id=(select count(distinct point) from TB where T.[point]<=[point]),
point,
[name]
from TB t
/*
id point name
----------- ----------- ----
1 100 张三
2 80 李四
2 80 王五
3 75 杨六
3 75 方七(5 個資料列受到影響)
*/