id title sid
1 xx 1
2 xxx 2
3 xxx 1
4 yyyy 2
5 fdjk 3
然后用一条查询,列出 sid值相同的最大一条数据
如
id title sid
3 xxxxx 1
4 yyyy 2
5 fdjk 3
16 个解决方案
#1
max(sid)
#2
用sid分组查询
#3
使用函数MAX()
#4
能写个具体语句吗
#5
Dim newconn, rs, Sql
Sql = "Select TITLE, Max(SID) AS MS From FORM Group By TITLE"
Call openNewConn("/XH_Database/Cs.mdb") 'Open CONN
Set rs = newconn.Execute(Sql)
While Not rs.Eof
'Response.Write "ID = " & rs(0).Value & " "
Response.Write "TITLE = " & rs("TITLE").Value & " "
Response.Write "SID = " & rs("MS").Value & " <br />"
rs.MoveNext: Wend
rs.Close: Set rs = Nothing
Call closeConn 'Close CONN
Sql = "Select TITLE, Max(SID) AS MS From FORM Group By TITLE"
Call openNewConn("/XH_Database/Cs.mdb") 'Open CONN
Set rs = newconn.Execute(Sql)
While Not rs.Eof
'Response.Write "ID = " & rs(0).Value & " "
Response.Write "TITLE = " & rs("TITLE").Value & " "
Response.Write "SID = " & rs("MS").Value & " <br />"
rs.MoveNext: Wend
rs.Close: Set rs = Nothing
Call closeConn 'Close CONN
#6
sql="select id,title,sid from 表 where [id] in (select MAX([id]) from 表 group by sid) order by id desc"
#7
楼上的SQL出现的效果,如果按LZ的数据测试的话那么结果是3条数据,分别为Id = 1
Id = 2 Id = 3
Id = 2 Id = 3
#8
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
#9
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
#10
MAX([id])
汗,刚没看清楚。。竟然MAX(ID)
LZ要MAX(SID)
你还说你测试了?
你测试的结果你看了么?
如果输出rs(0).Value的话那么就是
5
4
3
应该是
5
4
2
因为你这个是取同类ID最大的。。
2的SID比3的SID大但是ID却不如3的ID大,所以。。。。
汗,刚没看清楚。。竟然MAX(ID)
LZ要MAX(SID)
你还说你测试了?
你测试的结果你看了么?
如果输出rs(0).Value的话那么就是
5
4
3
应该是
5
4
2
因为你这个是取同类ID最大的。。
2的SID比3的SID大但是ID却不如3的ID大,所以。。。。
#11
难道楼主不是想取SID相同记录中ID值最大的吗?
id title sid
1 xx 1
2 xxx 2
3 xxx 1
4 yyyy 2
5 fdjk 3
输入
id title sid
5 fdjk 3
4 yyyy 2
3 xxxxx 1
不正确?
至于ID的排序把 ORDER BY id DESC 改为 ORDER BY id ASC
id title sid
1 xx 1
2 xxx 2
3 xxx 1
4 yyyy 2
5 fdjk 3
输入
id title sid
5 fdjk 3
4 yyyy 2
3 xxxxx 1
不正确?
至于ID的排序把 ORDER BY id DESC 改为 ORDER BY id ASC
#12
是输出,手误
#13
晕,我也不知道LZ什么意思。。。刚还以为要取相同TITLE里SID最大的呢。
#14
weiforest(dd) ( ) 信誉:100 Blog 2006-12-14 17:02:58 得分: 0
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
是对的
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
是对的
#15
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
确实可用,谢谢大家了
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
确实可用,谢谢大家了
#16
今天也用到了,谢谢上面的朋友
#1
max(sid)
#2
用sid分组查询
#3
使用函数MAX()
#4
能写个具体语句吗
#5
Dim newconn, rs, Sql
Sql = "Select TITLE, Max(SID) AS MS From FORM Group By TITLE"
Call openNewConn("/XH_Database/Cs.mdb") 'Open CONN
Set rs = newconn.Execute(Sql)
While Not rs.Eof
'Response.Write "ID = " & rs(0).Value & " "
Response.Write "TITLE = " & rs("TITLE").Value & " "
Response.Write "SID = " & rs("MS").Value & " <br />"
rs.MoveNext: Wend
rs.Close: Set rs = Nothing
Call closeConn 'Close CONN
Sql = "Select TITLE, Max(SID) AS MS From FORM Group By TITLE"
Call openNewConn("/XH_Database/Cs.mdb") 'Open CONN
Set rs = newconn.Execute(Sql)
While Not rs.Eof
'Response.Write "ID = " & rs(0).Value & " "
Response.Write "TITLE = " & rs("TITLE").Value & " "
Response.Write "SID = " & rs("MS").Value & " <br />"
rs.MoveNext: Wend
rs.Close: Set rs = Nothing
Call closeConn 'Close CONN
#6
sql="select id,title,sid from 表 where [id] in (select MAX([id]) from 表 group by sid) order by id desc"
#7
楼上的SQL出现的效果,如果按LZ的数据测试的话那么结果是3条数据,分别为Id = 1
Id = 2 Id = 3
Id = 2 Id = 3
#8
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
#9
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
#10
MAX([id])
汗,刚没看清楚。。竟然MAX(ID)
LZ要MAX(SID)
你还说你测试了?
你测试的结果你看了么?
如果输出rs(0).Value的话那么就是
5
4
3
应该是
5
4
2
因为你这个是取同类ID最大的。。
2的SID比3的SID大但是ID却不如3的ID大,所以。。。。
汗,刚没看清楚。。竟然MAX(ID)
LZ要MAX(SID)
你还说你测试了?
你测试的结果你看了么?
如果输出rs(0).Value的话那么就是
5
4
3
应该是
5
4
2
因为你这个是取同类ID最大的。。
2的SID比3的SID大但是ID却不如3的ID大,所以。。。。
#11
难道楼主不是想取SID相同记录中ID值最大的吗?
id title sid
1 xx 1
2 xxx 2
3 xxx 1
4 yyyy 2
5 fdjk 3
输入
id title sid
5 fdjk 3
4 yyyy 2
3 xxxxx 1
不正确?
至于ID的排序把 ORDER BY id DESC 改为 ORDER BY id ASC
id title sid
1 xx 1
2 xxx 2
3 xxx 1
4 yyyy 2
5 fdjk 3
输入
id title sid
5 fdjk 3
4 yyyy 2
3 xxxxx 1
不正确?
至于ID的排序把 ORDER BY id DESC 改为 ORDER BY id ASC
#12
是输出,手误
#13
晕,我也不知道LZ什么意思。。。刚还以为要取相同TITLE里SID最大的呢。
#14
weiforest(dd) ( ) 信誉:100 Blog 2006-12-14 17:02:58 得分: 0
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
是对的
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
刚测试过,绝对正确
是对的
#15
SELECT id, title, sid
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
确实可用,谢谢大家了
FROM 表
WHERE (id IN
(SELECT MAX([id])
FROM 表
GROUP BY sid))
ORDER BY id DESC
确实可用,谢谢大家了
#16
今天也用到了,谢谢上面的朋友