注册 登录
编程论坛 SQL Server论坛

怎么编写排名名次

jalonlovesja 发布于 2009-09-18 08:40, 1234 次点击
假如:A表:{B.ID,销售金额},B:{人员}
结果:
人员    销售金额    名次
aaaa     12334       1
bbbb     3453        2
cccc      324        3

想通过SQL语句这样显出上面的结果,应该要怎么编写?麻烦教下咯!

[ 本帖最后由 jalonlovesja 于 2009-9-18 08:52 编辑 ]
4 回复
#2
msgj2009-10-05 17:54
下面的程序只是演示,在实际程序中就用表格控件


Private Sub Form_Activate()
Adodc1.ConnectionString = cnstr
Adodc1.RecordSource = "SELECT b.人员,a.销售金额 FROM a,b WHERE a.ID=b.ID ORDER BY a.销售金额 DESC"
Adodc1.Refresh
End Sub
 
Public Function cnstr() As String
 cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\排名.mdb;Persist Security Info=True"
End Function
Private Sub Command1_Click()
Print "人员    销售金额   名次  "
Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.EOF = False And Adodc1.Recordset.BOF = False
Print Adodc1.Recordset(0); "    "; Adodc1.Recordset(1); "    "; Adodc1.Recordset.AbsolutePosition
Adodc1.Recordset.MoveNext
Loop
End Sub
#3
Vitamin19992009-10-15 10:45
你说的是用SQL写吧,这样写就哦了
select bb.人员,aa.销售金额,(select count(*) from A nn where nn.销售金额 >= aa.销售金额) as 名次 from A aa join B bb on aa.bID = bb.id
#4
bdx8082009-10-16 21:22
谢谢,学习,得分
#5
xiezeng2009-10-27 20:50
以下是引用jalonlovesja在18-9-2009 08:40:46的发言:

假如:A表:{B.ID,销售金额},B:{人员}
结果:
人员    销售金额    名次
aaaa     12334       1
bbbb     3453        2
cccc      324        3

想通过SQL语句这样显出上面的结果,应该要怎么编写?麻烦教下咯!
select * from A where obder by 名次
1