[SQL]Select COUNT(*) and COUNT(1) and COUNT('rainmaker') and COUNT(column)的差別

Select COUNT(*) and COUNT(1) and COUNT('rainmaker') and COUNT(column)的差別

請看以下的測試


create table a
(
c1 varchar(10),
c2 varchar(10)
)

insert a values('1', '1')
insert a values('2', '2')
insert a values(null, null)

select COUNT(*) from a
select COUNT(1) from a
select COUNT('rainmaker') from a
select COUNT(c1) from a

 

image

結論

COUNT(*) = COUNT(1) = COUNT('rainmaker') 可能不等於(如果該欄位有null值的話) COUNT(column)

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^