帮忙搞个查询!!!!感谢感谢
table: user
ID Name Stat
1 张三 0
2 张四 0
3 张一 0
4 张二 1
5 张五 1
6 张六 1
7 张七 1
8 张八 1
9 张九 0
希望通过一条查询得出:
statok (状态为1的记录)
maxmun (表中的最大ID值)
minmun (表中的最小ID值)
maxmunok (表中stat为1最大ID值)
minmunok (表中stat为1最小ID值)
在线等各位高人出着
------解决方案--------------------select
*,
(select max(id) from [user]) as maxmun,
(select min(id) from [user]) as minmun,
(select max(id) from [user] where Stat=1)as maxmunok,
(select min(id) from [user] where Stat=1)as minmunok
from [user]
where Stat=1
------解决方案--------------------select
ID,Name,Stat,
(select max(id) from [user]) as maxmun,
(select min(id) from [user]) as minmun,
(select max(id) from [user] where Stat=1)as maxmunok,
(select min(id) from [user] where Stat=1)as minmunok
from [user]
where Stat=1
这样。