那如何在一个sql语句中实现这样的要求?

解决方案 »

  1.   

    贴一段我写的统计商品数量的代码给你<?php
    //DataBase Info
    $dbhost = "localhost";  // DB Host
    $dbuser = "root";  // DB User
    $dbpasswd = "";  // DB User Password
    $dbname = "shop";  // DB Name$mylink=mysql_connect($dbhost,$dbuser,$dbpasswd);
    mysql_select_db($dbname,$mylink);
    $sql="select * from $tb_product where S_Id='$x'";
    $result=mysql_query($sql);
    $message_count=mysql_num_rows($result);
    ?>
      

  2.   

    select count(0) as t from tablename where field ='1'读取这个t的字段值即可
      

  3.   

    不是这样的,是我表达错了。我是要列出比如当字段first为1时的数据条数大于3时的数据的另一字段numbers的值。不知道说清楚没。如下表:
        +--------+----------+---------+
        | id     | first    | numbers | 
        +--------+----------+---------+
        | 1      |   1      |  10     | 
        | 2      |   0      |  21     | 
        | 3      |   0      |  57     | 
        | 4      |   1      |  18     | 
        | 5      |   0      |  16     | 
        | 6      |   1      |  50     | 
        | 7      |   1      |  78     | 
        | 8      |   0      |  34     | 
        +--------+----------+---------+
    就应该列出第7条数据的numbers的值78来
      

  4.   

    顶一下,高手都来看看啊。我是要列出比如当字段first为1时的数据条数大于3时的数据的另一字段numbers的值。不知道说清楚没。如下表:
        +--------+----------+---------+
        | id     | first    | numbers | 
        +--------+----------+---------+
        | 1      |   1      |  10     | 
        | 2      |   0      |  21     | 
        | 3      |   0      |  57     | 
        | 4      |   1      |  18     | 
        | 5      |   0      |  16     | 
        | 6      |   1      |  50     | 
        | 7      |   1      |  78     | 
        | 8      |   0      |  34     | 
        +--------+----------+---------+
    就应该列出第7条数据的numbers的值78来
      

  5.   

    估计用SQL语句无法实现这个功能,你可以先全部取出来,
    $conn=mysql_connect(....);//连接数据库
    mysql_select_db('...');//选择数据库
    $sql="select * from 表名 where first=1 order by id asc";
    $result=mysql_query($sql);//执行语句
    if(mysql_num_rows($result)>3){//判断是否大于三行。
        if(mysql_data_seek($result, 3)){//定位到第四行。
           while($f=mysql_fetch_array($result)){//循环取得数据,这里取得是从第四行到结束
              echo $f['number'];//输出取得的number列的值
           }
        }
    }
      

  6.   

    OK,解决了,谢谢各位,也谢谢ashen8615242,bigluckyfox,helloyou0,syre, missago, ghjhot