Join 连接-两个表

Join 连接-两个表,join,Join,我不熟悉数据库。我在两张桌子上遇到了一个奇怪的问题。请告诉我解决办法。请注意下面的场景 中间的桌子 prdcntrId(主键),prdcntrname 应用程序类型表 apptypeid(主键) prdcntreid(ProductCenter的外键) apptypname ProductCentre table || ApplicationType table || prdcntrId prdcntrna

我不熟悉数据库。我在两张桌子上遇到了一个奇怪的问题。请告诉我解决办法。请注意下面的场景

中间的桌子 prdcntrId(主键),prdcntrname

应用程序类型表 apptypeid(主键) prdcntreid(ProductCenter的外键) apptypname

ProductCentre table       ||            ApplicationType table
                          ||
 prdcntrId  prdcntrname   ||       apptypeid prdcntreid  apptypname
001          Delhi        ||          11          001           Busines
002          Mumbai       ||          12          003           Engg
003          Hyd          ||          13          001          Soft
                                      14          002         Science
最终结果应该是这样的 一个产品中心可以有任何类型的应用程序,比如德里可以有许多业务,软应用程序与孟买、海德相同

--------------------------------------------------------------------- prdcntrname Busines Engg Soft Science --------------------------------------------------------------------- Delhi 1 0 1 0 --------------------------------------------------------------------- Mumbai 0 1 0 1 --------------------------------------------------------------------- Hyd 0 1 0 0 --------------------------------------------------------------------- --------------------------------------------------------------------- prdcntrname企业工程软科学 --------------------------------------------------------------------- 德里1010 --------------------------------------------------------------------- 孟买01101 --------------------------------------------------------------------- 液压0 1 0 0 --------------------------------------------------------------------- 从这两个表中可以得出这个解决方案吗。请在这个场景中帮助我

谢谢, KK

您可以尝试使用

类似(Sql Server)的东西

你可以尝试使用

类似(Sql Server)的东西


如果“apptypname”类型是固定的,则这可以工作:

select
c.prdcntrname,
Busines = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Business'),
Engg = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Engg'),
Soft = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Soft'),
Science = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Science'),

from ProductCentre c
order by c.prdcntrname

如果“apptypname”类型是固定的,则这可以工作:

select
c.prdcntrname,
Busines = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Business'),
Engg = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Engg'),
Soft = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Soft'),
Science = (select count(*) 
           from ApplicationType at 
           where at.prdcntreid = c.prdcntreid and apptypname = 'Science'),

from ProductCentre c
order by c.prdcntrname

是的,有枢轴功能的不错,我同意。我昨天刚刚复习了PIVOT。是的,PIVOT功能不错。我同意。我昨天刚刚复习了一下。