select 5种子句: where 条件查询 group by 分组 having 筛选 order by 排序 limit 限制结果条数 --------------------- order by 排序 默认是升序asc 想要按降序排 desc 可以按多字段排序,如: order by 字段1 asc/desc,字段2 asc/desc; 取出所有商品,按价格从低到高:(默认) select goods_id,goods_name,shop_price from goods order by shop_price; 取出所有商品,按价格高到低: select goods_id,goods_name,shop_price from goods order by shop_price desc; 取出不是栏目3的所有商品,按cat_id来升序排,相同的cat_id栏目再按商品价格降序排 select cat_id,goods_name,shop_price from goods where cat_id != 3 order by cat_id,shop_price desc; ------------------------ limit 限制结果条数,在语句的最后。 通常和order by配合使用。 limit [offset],N offset 偏移量(可选,默认为0。如果不写,则相当于limit 0,N) N 取出的条数 取出商品最贵的前三个商品 select goods_name,shop_price from goods order by shop_price desc limit 3; 取出商品最贵的第三到第六个商品 select goods_name,shop_price from goods order by shop_price desc limit 3,3;
原文地址:http://1154179272.blog.51cto.com/10217799/1653246