mysql列舉統計 mysql 計算列舉值?

2021-10-19 06:45:46 字數 1145 閱讀 7462

您可以像這樣執行三個查詢:

select count(*)

from daily_individual_tracking

where sales = 'yes'

and daily_individual_tracking_date between '2010-01-01' and '2010-03-31'

或者,如果你想要,你可以像這樣一次獲得所有三個:

select (

select count(*)

from daily_individual_tracking

where sales = 'yes'

and daily_individual_tracking_date between '2010-01-01' and '2010-03-31'

) as sales_count, (

select count(*)

from daily_individual_tracking

where repairs = 'yes'

and daily_individual_tracking_date between '2010-01-01' and '2010-03-31'

) as repairs_count, (

select count(*)

from daily_individual_tracking

where shipping = 'yes'

and daily_individual_tracking_date between '2010-01-01' and '2010-03-31'

) as shipping_count

另一種方法是使用sum而不是count.您也可以嘗試這一點,看看它如何影響效能:

select

sum(sales = 'yes') as sales_count,

sum(repairs = 'yes') as repairs_count,

sum(shipping = 'yes') as shipping_count

from daily_individual_tracking

where daily_individual_tracking_date between '2010-01-01' and '2010-03-31'

mysql 列舉字段 MySQL欄位中的列舉

mysql欄位相信大家都有一些了解,下面將為您介紹的是mysql欄位中的列舉,希望對您學習mysql欄位方面能夠有所幫助。mysql欄位中的列舉 mysql create table meiju f1 enum 1 2 3 4 5 6 query ok,0 rows affected 0.92 se...

mysql 列舉與集合 mysql列舉和集合型別

列舉和集合型別 列舉 enum 型別,最多可以定義 65535 種不同的字串從中做出選擇,只能並且必須選擇其中一種,占用儲存空間是乙個或兩個位元組,由列舉值的數目決定 集合 set 型別,最多可以有 64 個成員,可以選擇其中的零個到不限定的多個,占用儲存空間是乙個到八個位元組,由集合可能的成員數目...

mysql統計資訊 概述MySQL統計資訊

mysql統計資訊的儲存分為兩種,非持久化和持久化統計資訊。一 非持久化統計資訊 非持久化統計資訊儲存在記憶體裡,如果資料庫重啟,統計資訊將丟失。有兩種方式可以設定為非持久化統計資訊 1 全域性變數,innodb stats persistent off 2 create alter表的引數,sta...