例如下面的 根據 self_wechatid 進行group by ,統計出 性別總數,男總數(gender = 1為男),女總數(gender = 2為男),不詳總數。
select
self_wechatid,
count(*) as total,
sum(if(gender = 1, 1, 0)) as man,
sum(if(gender = 2, 1, 0)) as girl,
(count(*) - sum(if(gender = 1, 1, 0)) - sum(if(gender = 2, 1, 0))
) as non
from
al_wx_contact
where
create_time > 1526730791
group by
self_wechatid;
insert into 表1(欄位1,欄位2,欄位3) select 欄位1,欄位2,欄位3 from 表1 where id=1
update sumholdtime s,province b set s.province = b.province where s.area_code=b.area_code;
update t_tc_telephone s,t_mobile_number_section b set s.province=b.province,s.city=b.city where s.area_code = b.area_code and s.area_code != '';
update t_non_tc_telephone s,t_mobile_number_section b set s.province=b.province,s.city=b.city where s.area_code = b.area_code and s.area_code != '';
delete t1 from t1,t2 where t1.id=t2.id
或delete from t1 using t1,t2 where t1.id=t2.id
delete t1 from t1 left join t2 on t1.id=t2.id where t2.id is null
或delete from t1,using t1 left join t2 on t1.id=t2.id where t2.id is null
delete t1,t2 from t1 left join t2 on t1.id=t2.id where t1.id=25
注意此處的delete t1,t2 from 中的t1,t2不能是別名
如:
delete t1,t2 from table_name as t1 left join table2_name as t2 on t1.id=t2.id where table_name.id=25
在資料裡面執行是錯誤的(mysql 版本不小於5.0在5.0中是可以的)
後續持續更新中
滴滴業務研發的精益實踐
精益生產 起源於豐田生產方式,它致力於在大量生產中實現多品種和高質量產品的低成本生產,隨著在製造業取得巨大成功,精益思想也逐步滲透到了各行各業,其中在軟體行業就演化出了很多新的理論,比如精益研發 devops等。精益生產堅信前置時間 lead time 是提公升產品質量 客戶滿意度和員工幸福感的最佳...
MySQL 業務查詢
1.查詢本月交易金額最高的卡號 select distinct cardid from transinfo where transmoney select from 2.查詢掛失賬號的客戶資訊 使用子查詢n或內連線查詢inner join select from userinfo where cus...
MySQL 儲存過程精講
在實際開發中,程式設計師相較於 dba 來說,對資料庫的理解不是特別的深。儲存過程相比於一般的 sql,可以做複雜的邏輯判斷,實現更加複雜表操作,比如根據一張表的資料去更新另一張表的資料 多張表資料比較結果等。本文將對 mysql 的儲存過程從零開始講解,結合實際案例,讓你從入門到實際運用 主要包括...