select * from 表名 where id like '201%' order by total desc limit 0,10
select count(*) from (select id from table order by total limit 0,10) as a where id like "201%"
请恕我驽钝,在php中,这个值怎么输出呢?
只需要输出 以201开头的记录的个数就可以了。先谢了!
select count(*) as amount from table where id like '201%' order by total desc limit 0,10;
<?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
<?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]; ?>试试这个呢
select count(*) as amount from table where id like '201%' order by total desc limit 10;
<?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]; ?>我试了,这个应该是行的
可能是我没有表述清楚我的目的。假设在数据表 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
我上面的: select count(*) from (select id from table order by total limit 0,10) as a where id like "201%"
select count(*) from (select id from table order by total desc limit 0,10) as a where id like "201%"
PHP 5 + MySQL 5我的 id 字段是用的 varchar,因为这个字段是不用来计算的。是不是这个有问题啊?where id like "201%"这一句中的双引号是不是写错了啊?应该用单引号的吧?
(select id from table order by total limit 0,10) as a
where id like "201%"
只需要输出 以201开头的记录的个数就可以了。先谢了!
$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
$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];
?>试试这个呢
$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];
?>我试了,这个应该是行的
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
select count(*) from
(select id from table order by total limit 0,10) as a
where id like "201%"
(select id from table order by total desc limit 0,10) as a
where id like "201%"
应该改为 echo $data[0];