首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接3个表

连接3个表
EN

Stack Overflow用户
提问于 2011-07-11 11:04:22
回答 1查看 51关注 0票数 0

我有三张桌子(CompanyProfile,IndustryTable,MainTable)

CompanyProfile

代码语言:javascript
复制
CompanyCode      CompanyName      IndustryCode
AAAA             Company A        3
BBBB             Company B        1
CCCC             Company C        4
DDDD             Company D        1
EEEE             Company E        1
GGGG             Company F        2

IndustryTable

代码语言:javascript
复制
IndustryCode     IndustryName     status
1                Manufacturing    ACTIVE
2                Sales            ACTIVE
3                Logistics        ACTIVE
4                Energy           DEACTIVATED

MainTable

代码语言:javascript
复制
CompanyCode  field2
AAAAA        SampleRecord1
AAAAA        SampleRecord2
DDDDD        SampleRecord3
CCCCC        SampleRecord4
EEEEE        SampleRecord5

现在,我需要一个查询来从MainTable Group IndustryTable.IndustryCode获得所有的IndustryTable.IndustryCode(仅为活动的),因此上面的示例应该提供以下输出

代码语言:javascript
复制
IndustryCode     IndustryName     RecordCount    (Explanation)
1                Manufacturing    2              -Record 3 and 5
2                Sales            0              
3                Logistics        2              -Record 1 and 2

记录4 (CCCCC)将不会显示,因为IndustryTable.IndustryCode 4已停用

EN

回答 1

Stack Overflow用户

发布于 2011-07-11 11:40:21

有点像

select industrycode, industryname, count(*) as total from companyprofile t1 join industry table t2 join maintable t3 where t1.companycode=t3.companycode and t1.industrycode=t2.industrycode and t2.status="ACTIVE" group by industrycode

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6649132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档