Select ID = (Select Count(userid) From A Where userid <= T.userid), * From A T
解决方案 »
- 统计某列的值在表中出现的次数
- 请大家看看我这个sql update 语句怎么写呀?
- 那里有SQL sp4补丁下载?
- 在再请教一个问题
- bcp导入DBF到sql的问题
- 查询到的 @F1 是条Insert语句,怎么样才能使用!!!
- SQL Server企业版为何导出EXCEL时提示无法初始化链接服务器 "(null)" 的 OLE DB 访问接口 "MICROSOFT.JET.OLEDB.
- 这样的SQL语句该怎么写?
- 请问各位大虾,在sql server里,如果我想让一个字段的值递增,如1、2、3、4……,应该怎么办?高分相赠!
- 学会SQL Server编程需要多少时间?
- 一个数据查询问题(请人指教)!
- 一个捆扰我好久的sql语言问题,知道的请进!有高分
(ID Int Identity(1, 1),
IText Varchar(10))
GO
Insert A Select '01'
union All Select '02'Select Max(IText) From A
Select SUM(Cast(IText As Int)) From A
GO
Drop Table A表
Select Max(字段) From 表
Select Max(Cast(字段 As Int)) From A
Select SUM(Cast(字段 As Int)) From A
GO现有数据库中A表,该表包含userid(主键)、username、pssword三个字段,
现有数据
001 liu 123
003 wang 123
008 zhang 456
009 xia 785现在要做查询查询结果如下:1 001 liu 123
2 003 wang 123
3 008 zhang 456
4 009 xia 785想问这个查询该怎么做?不可以建临时表,只可要sql语句。数据库是sqlServer2000
Select ID = (Select Count(userid) From A Where userid <= T.userid), * From A T
Create Table A
(userid Char(3) Primary Key,
username Varchar(20),
pssword Varchar(20))
Insert A Select '001', 'liu', '123'
Union All Select '003', 'wang', '123'
Union All Select '008', 'zhang', '456'
Union All Select '009', 'xia', '785'
GO
Select ID = (Select Count(userid) From A Where userid <= T.userid), * From A T
GO
Drop Table A
--Result
/*
ID userid username pssword
1 001 liu 123
2 003 wang 123
3 008 zhang 456
4 009 xia 785
*/
Create Table A
(userid Char(3) Primary Key,
username Varchar(20),
pssword Varchar(20))
Insert A Select '001', 'liu', '123'
Union All Select '003', 'wang', '123'
Union All Select '008', 'zhang', '456'
Union All Select '009', 'xia', '785'
GO
Select ID = (Select Count(userid) From A Where userid <= T.userid), * From A T
GO
Drop Table A
--Result
/*
ID userid username pssword
1 001 liu 123
2 003 wang 123
3 008 zhang 456
4 009 xia 785
*/