当前位置: 首页 > news >正文

网站设计素材坚决把快准严细实要求落实到位

网站设计素材,坚决把快准严细实要求落实到位,好买卖做网站,文章类网站选什么内容语法 select [distinct] 列名1#xff0c;列名2 as 别名... from数据表名 where组前筛选 group by分组字段 having组后筛选 order by排序的列 [asc | desc] limit 起始索引#xff0c;数据条数 测试数据 # 建测试表 create table products (id int primary key a…语法 select [distinct] 列名1列名2 as 别名... from数据表名 where组前筛选 group by分组字段 having组后筛选 order by排序的列 [asc | desc] limit 起始索引数据条数 测试数据 # 建测试表 create table products (id int primary key auto_increment, -- 商品idname varchar(24) not null, -- 商品名称price decimal(10, 2) not null, -- 商品价格score decimal(5, 2), -- 商品评分可以为空is_self varchar(8), -- 是否自营category_id int -- 商品类别id );create table category (id int primary key auto_increment, -- 商品类别idname varchar(24) not null -- 类别名称 );# 添加测试数据 insert into category values (1, 手机),(2, 电脑),(3, 美妆),(4, 家居);insert into products values (1, 华为mate50, 5499.00, 9.70, 自营, 1),(2, 荣耀80, 2399.00, 9.50, 自营, 1),(3, 荣耀80, 2199.00, 9.30, 非自营, 1),(4, 红米note 11, 999.00, 9.00, 非自营, 1),(5, 联想小新14, 4199.00, 9.20, 自营, 2),(6, 惠普战66, 4499.90, 9.30, 自营, 2),(7, 苹果air13, 6198.00, 9.10, 非自营, 2),(8, 华为matebook14, 5599.00, 9.30, 非自营, 2),(9, 兰蔻小黑瓶, 1100.00, 9.60, 自营, 3),(10, 雅诗兰黛粉底液, 920.00, 9.40, 自营, 3),(11, 阿玛尼红管405, 350.00, null, 非自营, 3),(12, 迪奥996, 330.00, 9.70, 非自营, 3); 简单查询 -- ---------------------- 案例1: 简单查询 ---------------------- -- 1. 查看表中所有的数据. select id, name, price, score, is_self, category_id from products; select * from products; # 效果同上-- 2. 查看指定列, 例如: 商品名, 价格 select name, price from products;-- 3. 给列, 表起别名. select name as 商品名, price as 商品单价, is_self from products as p; select name as 商品名, price 商品单价, is_self from products p; # 细节1: as可以省略不写 select name as 商品名, price 商品单价, is_self from products p; # 细节2: 别名和关键字重名要加反引号 select name as desc, price 商品单价, is_self from products p; # 细节2: 别名和关键字重名要加反引号-- 4. 去重查询. distinct, 查看所有商品的类别. select distinct category_id from products; select distinct category_id, is_self from products; # 细节: distinct后边有多列, 则是把多列作为1个整体来去重的. 条件查询 条件运算符 比较运算符、、、 select * from products where price 4199; -- 查询价格大于4199的手机 select * from products where price ! 4199; -- 查询价格不等于4199的手机信息 select * from products where price 4199; -- 查询价格不等于4199的手机信息 逻辑运算符AND(并且)、OR(或者)、NOT(非、取反) select * from products where price 2000 and price select * from products where price 4000; -- 查询价格在2000之下的手机信息和4000之上的手机信息 select * from products where not (price 4000); -- 查询价格在2000到4000的手机信息 not的意思是给条件取反 LIKE模糊查询 select * from products where name like 荣耀% ; -- 查询名称以荣耀开头的手机信息 select * from products where name like %mate%; -- 查询名称包含mate的手机信息 select * from products where name like %1_; -- 查询名称倒数第二位是1的手机信息 范围查询 select * from products where price between 2000 and 4000;-- 查询价格在2000到4000的手机信息 select * from products where price in (2199, 2399); -- 查询价格2199, 2399的手机信息 空值判断IS NULL 和 IS NOT NULL 注意空值的判断一定不能使用 或 ! select * from products where score is null; -- 查询score为null的手机信息 select * from products where score is not null; -- 查询score不为null的手机信息 常用的聚合函数 注意聚合函数的计算会忽略NULL值 COUNT(col)求指定列的总记录数 count计数; select count(*) from products; -- 查询总共有多少行 面试题count(*)count(1)count(列) 区别 却别1count(列)不会统计null值count(*),count(1) 会统计null值 却别2效率问题count(主键列) count(1)count(*)count(列) MAX(col)求指定列的最大值 maximum最大值; 注意如果统计的是字符串则返回字符串长度最大的列 MIN(col)求指定列的最小值 minimum最小值; SUM(col)求指定列的和 sum总和; AVG(col)求指定列的平均值 average平均数; 注意平均数小数比较多需要保留特定位数可以使用round1234.12,2 select round(avg(price),2) as round2_avg_price from table_name; select max(price), min(price),round(avg(price),2),sum(price) from products; -- 依次查询最高价格最低价格价格平均值价格总量 排序 asc 升序排序desc 降序排序 select * from products order by score desc , price asc ; # 按score 降序price 升序 select * from products order by price asc; --按价格升序排列 select * from products order by price desc; --按价格降序排列 select * from products order by category_id asc, score desc; --先按category_id升序排列如果category_id相同则安score降序排列 分组查询 注意分组查询的查询列只能出现分组字段聚合函数 select 分组字段1分组字段2, ... ... , 聚合函数1聚合函数2, ... ... from table_name group by 分组字段1分组字段2, ... ... select category_id,count(*) as 每组个数 from products group by category_id ; -- 分组查询综管有三组并显示出每组的个数 再强调下select 后面跟的列只能是后面group by 用的列与聚合函数。 select count(*) as 每组个数, round(avg(price),2) as 每组价格平均数, max(price) as 每组最高价格, min(price) as 每组最低价格 from products group by category_id ; -- 这个查询是不是就有意义了。 having 和 where 有什么区别 having 是对分组聚合之后的结果进行过滤where是在对分组前的数据进行过滤 where - group by -聚合 - habing having 后面可以使用聚合函数统计函数where后面不可以使用聚合函数 select count(*) as 每组个数, round(avg(price),2) as 每组价格平均数, max(price) as 每组最高价格, min(price) as 每组最低价格 from products group by category_id having max(price) 3000; --这里的max(price) 可以写成 【每组最高价格】不能写成 【每组最高价格】 -- 查询出每组最高价格小于3000 的统计信息 limit 1、起始索引默认是从0开始如果你写的代码起始索引为0则可以不写 select * from products limit 2; -- 查询前两行数据 select * from products limit 1,1; -- 查询跳过第一行后的一个数据 这个分页自己学习试试有什么不明白的可以留言 查询某也数据limit 页数-1*页条数页条数 求总页数 方法一(总条数页条数-1) / 页条数 方法二 总行数%页条数0 总行数/条数1 总行数%页条数0 总行数/条数 方法三ceil (总条数/总行数) 常用函数 round1234.1234,122 #四舍五入保留2位小数 ceil123.111 #向下取整舍去小数
http://www.hkea.cn/news/14514487/

相关文章:

  • 备案 个人网站聊城网站建设报价
  • 提供网站建设备案网站怎么做会让神马搜索到
  • 福永营销型网站多少钱网站如何建立数据库
  • 企业网站建设示范平台有没有免费的网站
  • 网站推广哪个平台好html编辑器的功能介绍
  • 做自媒体查找素材的网站定制营销产生的原因
  • 假冒建设厅网站wordpress 翻页没内容
  • 河南省住房和城乡建设门户网站个旧市建设局网站
  • 网站开发的现状及研究意义asp网站开发pdf
  • 南京企业网站设计制作营销型网站建设模板下载
  • 怎么建立一个网站搜关键词会跳出东莞市研发网站建设企业
  • 微信做明天展现网站要多少钱搭建本地视频网站
  • 网站换服务器要怎么做怎么开电商
  • 网站内容包括哪些系统软件有哪些?
  • 长春微信做网站制作一个自适应网站源码
  • 网站开发及设计网站建设的风格
  • 黄冈商城网站建设哪家好在线做爰视频网站
  • 河南企业做网站网站上的视频直播是怎么做的呢
  • 学做ppt的网站重庆如何快速制作一个网站
  • dw怎么做网站教程房地产项目营销策划方案
  • 自己的公网ip可以做网站清河网站建设公司
  • 网站运营与管理第二版网站的所有权
  • 肇庆微网站网络推广培训哪里好
  • 海安县城乡建设局网站成都网站建设名录
  • 上海网站建设特点哪些网站的网站怎么做的
  • 网站的建设参考文献wordpress页面文章区别
  • 园林景观设计案例网站公网ip 做网站
  • cgi做的网站餐饮公司网站建设的特点
  • 全国建设注册中心网站精准营销的作用
  • 网站制作 潍坊深圳品牌策划机构