您现在的位置是:首页 > 学无止境
SQL小技巧
数据库结构如下:
要求:一句SQL实现,分别统计type1,2,3,4 一共多少money (group by uid)
原先做法:分开查询 然后用php合并结果,如
select sum(money) form test where type = 1 group by uid
s...
要求:一句SQL实现,分别统计type1,2,3,4 一共多少money (group by uid)
原先做法:分开查询 然后用php合并结果,如
select sum(money) form test where type = 1 group by uid
s...
数据库结构如下:
要求:一句SQL实现,分别统计type1,2,3,4 一共多少money (group by uid)
原先做法:分开查询 然后用php合并结果,如
select sum(money) form test where type = 1 group by uid select sum(money) form test where type = 2 group by uid select sum(money) form test where type = 3 group by uid select sum(money) form test where type = 4 group by uid现在要求一句SQL。
SELECT uid, SUM( IF(`type`=1, money, 0 ) ) AS `BuyByCash`, SUM( IF (`type`=3, money, 0 ) ) AS `BuyByCard`, SUM( IF( `type` IN (1,3), money, 0 ) ) AS `BuyByCashAndCard`, SUM( IF(`type`=2, money, 0 ) ) AS `SellByCash`, SUM( IF(`type`=4, money, 0 ) ) AS `SellByCard`, SUM( IF( `type` IN (2,4), money, 0 ) ) AS `BuyByCashAndCard`, SUM(money) AS `Amount`, COUNT(*) AS `DataNums` FROM `test` group by `uid`解决了
下一篇:开源分词程序
文章评论
- 登录后评论
点击排行
-
php-fpm安装、配置与优化
转载自:https://www.zybuluo.com/phper/note/89081 1、php中...
-
centos下postgresql的安装与配置
一、安装(以root身份进行)1、检出最新的postgresql的yum配置从ht...
-
Mysql的大小写敏感性
MYSQL在默认的情况下查询是不区分大小写的,例如:CREATE TABLE...
-
关于URL编码
转载自:http://www.ruanyifeng.com/blog/2010/02/url_encoding....
-
header中的Cache-control
网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的...