0

我有两张这样的桌子

Table 1: MedicineType  
MedicineTypeID MedicineTypeName
TE001         | HIV
TE002         | AIDS

Table 2: MsMedicine
MedicineID MedicineTypeID MedicineName
ME001     | TE001        | HIVgood 
ME002     | TE001        | HIVsmart
ME003     | TE002        | AIDSawesome

如何显示 MedicineTypeID、MedicineTypeName 和 MedicineCount(来自每个 MedicineType 上 MedicineID 的数量)示例:

MedicineTypeID MedicineTypeName MedicineCount
        TE001 | HIV            | 2
        TE002 | AIDS           | 1
4

2 回答 2

3
Select mt.MedicineTypeID, mt.MedicineTypeName, Count(m.MedicineID) as MedicineCount
From MedicineType
Inner Join MSMedicine m On mt.MedicineTypeID = m.MedicineTypeID
Group By mt.MedicineTypeID, mt.MedicineTypeName
于 2013-05-24T21:21:37.873 回答
0

select MedicineTypeID,MedicineTypeName,count(*) as MedicineCount from MedicineType join MsMedicine on MedicineType.MedicineID=MsMedicine.MedicineID group by MedicineTypeID,MedicineTypeName

于 2013-05-24T21:19:06.023 回答