select count(
select total from 数据表 where id like "201%" order by total limit 0,10)
from 数据表

解决方案 »

  1.   

    select * from 表名 where id like '201%' order by total desc limit 0,10
      

  2.   

    select count(*) from 
    (select id from table order by total limit 0,10) as a
    where id like "201%"
      

  3.   

    请恕我驽钝,在php中,这个值怎么输出呢?  
     
    只需要输出  以201开头的记录的个数就可以了。先谢了!
      

  4.   

    select count(*) as amount from table where id like '201%' order by total desc limit 0,10;
      

  5.   

    <?php
    $db = mysql_connect("localhost","root","");
    mysql_query("SET NAMES 'utf8'");
    mysql_select_db("testdb");
    $sql = "select count(*) as amount from test200701 where id like '201%' order by total desc limit 0,10;";
    $result = mysql_query($sql,$db);
    $data = mysql_fetch_array($result);
    echo $data["0"];
    ?>
    以上代码,返回如下错误信息:
    arning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
      

  6.   

    <?php
    $db = mysql_connect("localhost","root","");
    mysql_query("SET NAMES 'utf8'");
    mysql_select_db("testdb");
    $sql = "select count(*) as amount from test200701 where id like '201%' order by total desc limit 0,10;";
    $result = mysql_query($sql,$db);
    $data = mysql_fetch_array($result);
    echo $data[amount];
    ?>试试这个呢
      

  7.   

    kof820()的代码可以运行,但是结果好像有问题。我在自己的电脑上测试,居然得出了 48 这个数字。
      

  8.   

    select count(*) as amount from table where id like '201%' order by total desc limit 10;
      

  9.   

    <?php
    $db = mysql_connect("localhost","root","");
    mysql_query("SET NAMES 'utf8'");
    mysql_select_db("testdb");
    $sql = "select count(*) from 
    (select id from table order by total limit 0,10) as a
    where id like "201%"";
    $result = mysql_query($sql,$db);
    $data = mysql_fetch_array($result);
    echo $data[amount];
    ?>我试了,这个应该是行的
      

  10.   

    可能是我没有表述清楚我的目的。假设在数据表 test2007 中有两个字段 id 和 total,数据如下:
    id   total
    20102  5200
    20118  3400
    20143  6100
    20150  2300
    20224  9000
    20276  7500
    20201  4750
    20345  3200
    20421  5600
    20499  1200
    20512  4250现在需要按 total 降序排列后,求出以201开头的占了几个。以上数据求出的值应该为 4
      

  11.   

    我上面的:
    select count(*) from
    (select id from table order by total limit 0,10) as a
    where id like "201%"
      

  12.   

    select count(*) from
    (select id from table order by total desc limit 0,10) as a
    where id like "201%"
      

  13.   

    PHP 5 + MySQL 5我的 id 字段是用的 varchar,因为这个字段是不用来计算的。是不是这个有问题啊?where id like "201%"这一句中的双引号是不是写错了啊?应该用单引号的吧?
      

  14.   

    找到问题了。最后一句 echo $data[amount];
    应该改为 echo $data[0];