首页 > 代码库 > 数据查询相关函数
数据查询相关函数
DISTINCT() 过滤重复 COUNT() 统计个数 SELECT COUNT(DISTINCT(cateid)) FROM cs_goods ORDER BY cateid SELECT COUNT(*) FROM cs_goods SUM() 求和 求price列总和 SELECT SUM(price) FROM cs_goods 求每个月总销售额 SELECT SUM(price),SUBSTRING(FROM_UNIXTIME(createtime),1,7) AS ymonth FROM cs_goods GROUP BY ymonth; 求每天总销售额 SELECT SUM(price),DATE(FROM_UNIXTIME(createtime)) AS ymonth FROM cs_goods GROUP BY ymonth ORDER BY ymonth DESC; 求每天销售额大于100的记录 SELECT SUM(price) AS total,DATE(FROM_UNIXTIME(createtime)) AS ymonth FROM cs_goods GROUP BY ymonth HAVING total>100 ORDER BY ymonth DESC; AVG() 求平均 求所有商品平均单价 SELECT AVG(price) FROM cs_goods; 求每个分类下商品平均单价 SELECT AVG(a.price),a.cateid,b.category FROM cs_goods a INNER JOIN cs_category b ON(a.cateid=b.id) GROUP BY cateid; MAX() 求最大值 求每个分类下最高单价 SELECT MAX(a.price),a.cateid,b.category FROM cs_goods a INNER JOIN cs_category b ON(a.cateid=b.id) GROUP BY cateid; MIN() 求最小值 求每个分类下最小单价 SELECT MIX(a.price),a.cateid,b.category FROM cs_goods a INNER JOIN cs_category b ON(a.cateid=b.id) GROUP BY cateid;
数据查询相关函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。