今天基本完成了專案的模組的基本功能,剩下的就是對專案的吃透,對各種工具類的掌握,其中sql語句的書寫就顯得很重要了,特別是新的任務就是 寫乙個統計板塊,sql語句基本從網上各大扒,基本已經成型,上沒有完成的是對sql語句執行完之後得到的資料的封裝並且**給前端
現總結今天的sql函式
select sum(case when sys_user.uname ='超級管理員' then 1 else 0 end) ,
sum(case when biz_order.uid = '21' then 1 else 0 end) ,
sum(case when biz_order.uid = 'qiuzhilinceshi' then 1 else 0 end)
from biz_order
left join sys_user on sys_user.uid = biz_order.uid
where year(biz_order.oacceptancedate)between '2017' and '2018';
group by biz_order.uid
這是乙個列轉行的方式select
sum(case month(biz_order.oacceptancedate) when '1' then 1 else 0 end) as january,
sum(case month(biz_order.oacceptancedate) when '2' then 1 else 0 end) as february,
sum(case month(biz_order.oacceptancedate) when '3' then 1 else 0 end) as march,
sum(case month(biz_order.oacceptancedate) when '4' then 1 else 0 end) as april,
sum(case month(biz_order.oacceptancedate) when '5' then 1 else 0 end) as may,
sum(case month(biz_order.oacceptancedate) when '6' then 1 else 0 end) as june,
sum(case month(biz_order.oacceptancedate) when '7' then 1 else 0 end) as july,
sum(case month(biz_order.oacceptancedate) when '8' then 1 else 0 end) as august,
sum(case month(biz_order.oacceptancedate) when '9' then 1 else 0 end) as september,
sum(case month(biz_order.oacceptancedate) when '10' then 1 else 0 end) as october,
sum(case month(biz_order.oacceptancedate) when '11' then 1 else 0 end) as november,
sum(case month(biz_order.oacceptancedate) when '12' then 1 else 0 end) as december
from biz_order
where year(biz_order.oacceptancedate)='2018';
以上就是我的專案涉及到的行轉列的地方 MySql學習總結
mysql 5.1參考手冊 使用筆記 除標準sql語言外 1 啟動指令碼位置 選項檔案位置 如果使用rpm包安裝指令碼位置在 etc init.d mysqld 選項位置 etc my.cnf 2 啟動服務方法 啟動服務 service mysqld start 開機自動啟動 chkconfig m...
mysql學習總結
mysql常用命令 建立表a,複製表b的資料結構,不複製資料 create table a like b 複製表b的資料內容到表a中 前提是表a與表b資料結構一致 insert into a select from b 檢視表a的建立語句 show create table a 檢視表a的資料結構 ...
mysql學習總結
一 innodb特點 優點 1 支援事務 2 行鎖 3 支援外來鍵 缺點 1 不支援全文索引 二 myisam blob和text列可以被索引。可以把資料檔案和索引檔案放在不同目錄,用data directory和index directory選項create table以獲得更高的速度 mysql...