Tag: count

  • MySQL: How To Count Rows But Still Show All The Rows?

    之前寫過 MySQL: Displaying Rows With COUNT 0 With Group By,用於強制顯示 Count() 為 0 的資料。最近又看到另一種寫法,因為我自己很少這麼寫,所以留個筆記。 SELECT col1, (SELECT COUNT(*) FROM table1 t1 WHERE t1.id = t2.t1_id) as Total FROM table2 t2 GROUP BY t2.id; 把子查詢放在 SELECT 敘述。試了一下,這種寫法的查詢速度會比單純的 left join 慢上許多,實際應用要視資料筆數來決定。

  • Git: How to count member's commits

    在 Git 裡計算 commits 數量個人是覺得沒什麼意義,頂多就是看著數字,滿足一下虛榮心吧。跟看磁碟重組的小方塊差不多。 $ git shortlog -s -n 65 CQ 34 Robin 12 Diro 8 micky 類似這樣,參考參考。 [Updated: 12-11-2013] 如果想查詢全部共有多少 commits,可以用以下指令: $ git rev-list HEAD –count 119

  • MySQL: Displaying Rows With COUNT 0 With Group By

    MySQL 裡用 Count 和 Group By 來做統計是常用的寫法。舉例來說,以下兩個 table,一個紀錄公司行號的資料,一個紀錄員工資料。 Company id company 1 Google 2 Microsoft Employee id employee company 1 Jack Google 2 Eric Microsoft