PHP+mysql常用查询语句集合

PHP 1841 0 2012-08-21

PHP+mysql常用查询语句集合

一、查询表中最小的数据
select id,min(price) from table where id=8 group by price

二、查询指定某数之间
select id,price from table where id=8 and (price between {$sp} and {$ep})

三、多表查询
select hotel.* from hotel,room where hotel.id=room.j_hid order by hotel.id asc

四、查询重复数据且只输出一条
select *,count(distinct hid) from room group by j_hid

五、时间段查询
select * from tablename where date between '{$stime}' and '{$etime}'

六、重复记录查询
//列出所有记录,如有重复的只输出一条
$sql="select *, count(distinct j_name) from table group by j_name";

//只列出重复的数据
$sql='select id,j_name,count(*) from table group by j_name having count(*)>1';

上一篇:PHP浏览frameset框架页面时显示空白解决方法

下一篇:分享一个简单明了的PHP数组分页,还有实例哦!

讨论数量:0

请先登录再发表讨论。 2024-04-25

天涯网魂
3 杠 5 星
TA 的文章
TA 的随言
TA 的资源链