table: userID 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值)
在线等各位高人出着

解决方案 »

  1.   

    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
      

  2.   

    #1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near
      

  3.   

    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
    这样。
      

  4.   

    #1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select max(id) from [user]) as maxmun,
    (select min(id) from [u 
      

  5.   

    我的mysql版本是MySQL 4.0.21,不会是版本的问题吧???