[SQL ] 數量統計問題?

作者: joedenkidd (優質的藍色射手)   2014-07-11 10:59:56
Dear All
A Table(a)
name station
A station1
A station2
B station1
C station1
B Table (station1)
name qty
A 10
B 20
select count(*) from station1 group by name
結果:
A 10
B 20
但是
select distinct a.name,count(station1.*) from a left join station on a.name=station.name group by a.name
結果
A 20
B 20
看來是因為 a table name=A 出現兩次
如果說用
select distinct a.name,count(station1.*) from a left join station on a.name=station.name where a.name='station1' group by a.name
A 10

Links booklink

Contact Us: admin [ a t ] ucptt.com