SQL用于查询具有两个子表的父表中的行,如果不存在子行,则使用空值(SQL to query rows from parent tables with two child tables, with blank values if no child row exists)
我有三个表,一个父项和两个子项,这两个子项使用ID列与父项具有FK关系,并且每个父行可能有0到n个子行。 我需要生成一个查询,该查询将从所有三个表生成一个数据结果集。
如果子行不存在,则该表的字段应为空,否则,这些字段应具有适当的值。
Table A Table B Table C -------- ------- ------- ID (PK) A_ID (FK) A_ID (FK) DataA1 DataB1 DataC1 DataA2 DataB2 DataC2
这个查询:
select * from A,B,C where A.ID = B.A_ID and A.ID = C.A_ID
将仅返回A中存在子行B和C的行。 我想从A返回行,其中对于A.ID,存在子行B或子行C. 如果B不存在行,则B.DataB1和B.DataB2应为null或空白,并且如果不存在C的行,则类似。
I have three tables, a parent and two children, the two children have FK releationship to the parent using an ID column, and there may be 0 to n child rows for each parent row. I need to produce a query that will generate a single result set of data from all three tables.
If the child row doesn't exist, the fields for that table should just be blank, otherwise, these fields should have the appropriate values.
Table A Table B Table C -------- ------- ------- ID (PK) A_ID (FK) A_ID (FK) DataA1 DataB1 DataC1 DataA2 DataB2 DataC2
This query:
select * from A,B,C where A.ID = B.A_ID and A.ID = C.A_ID
will return only rows from A where both child rows B and C exist. I want to return rows from A where either child row B or child row C exists for A.ID. If no row for B exists, B.DataB1 and B.DataB2 should be null or blank, and similarly if no row for C exists.
原文:https://stackoverflow.com/questions/13818785
最满意答案
注入对象图的配置完全取决于实际使用它的应用程序的需求。 使用容器的要点是能够在运行时配置依赖关系 - 库不知道如何使用它。
图书馆类应该以允许你使用你喜欢的任何容器的方式编写,或者按照消费者认为合适的方式使用穷人的依赖注入。 将一个库连接到一个容器是一种气味。
The configuration of an injected object graph is entirely dependent on the needs of the application that actually uses it. The point of using the container is to be able to configure dependencies at runtime - a library doesn't know anything about how it's going to be used.
Library classes should be written in a way that allows you to use any container you like, or poor-man's-dependency-injection as the consumer sees fit. Coupling a library to a container is a smell.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
现在已经如Mauricio所指出的那样进行了修正(添加了这个答案以便可以关闭该问题) That is now fixed as Mauricio pointed out (adding this answer so that the question can be closed)
-
注入对象图的配置完全取决于实际使用它的应用程序的需求。 使用容器的要点是能够在运行时配置依赖关系 - 库不知道如何使用它。 图书馆类应该以允许你使用你喜欢的任何容器的方式编写,或者按照消费者认为合适的方式使用穷人的依赖注入。 将一个库连接到一个容器是一种气味。 The configuration of an injected object graph is entirely dependent on the needs of the application that actually uses it. Th ...
-
对的,这是可能的。 默认组件激活器仅查找公共构造函数。 您可以为该组件提供自定义组件激活器,以考虑内部构造函数,或者使用例如工厂来激活组件: var container = new WindsorContainer() .AddFacility
() .Register( Component.For () .UsingFactoryMethod( () => new Foo() ) ); var fo ... -
据我所知, PerWebRequestLifestyle需要一个IHttpModule,以便它可以捎带init方法和HttpApplication事件 ,如BeginRequest 。 一切似乎都有效的原因是因为模块已经初始化,因此PerWebRequestLifestyle正常运行。 但是,如果您没有包含注册模块,为什么会这样呢? 我怀疑它是遗留指令,并且容器将自己尝试注册 ,但这没有明确记录。 如果我们在CastleWindsor中查看,我们会找到名为Castle.MicroKernel.Lifesty ...
-
在Castle Windsor的其他课程之间共享课程实例(Sharing instance of class between other classes in Castle Windsor)[2022-06-02]
如果要在A的b和c依赖关系之间共享相同的D实例,那么这应该足够了: class A { public A(B b, C c) { } } class B { public B(D d) { } } class C { public C(D d) { } } ... container.Register(Component.For().LifeStyle.Custom ()); A a = container.Resolve( ... -
就在这里: Component.For
().OnCreate(foo => foo.WhateverMethodYouWant()); 详细信息在文档中 。 Yes there is: Component.For ().OnCreate(foo => foo.WhateverMethodYouWant()); The details are in the documentation. -
NServiceBus使用Castle Windsor中的Scoped生活方式功能来实现儿童容器功能,在这里阅读有关范围的生活方式: http : //docs.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx 。 因此,瞬态行为就像瞬态一样,单身人士会像单身人士一样行事,范围会像单身人士服务总线请求一样行事。 我们为ISession和单身人士使用有限范围的生活方式,其余99%为单身人士。 我很少需要瞬变,至少在做网络应用时。 为什么您希望组件根据其 ...
-
我将使用ConfigurationManager.GetSection(“castle”)探测app.config(即,如果您使用仅XML配置) I would probe the app.config with a ConfigurationManager.GetSection("castle") (that is, if you use XML-only configuration)
-
自4.5以来的所有.NET版本都已到位, 如您所见 。 这意味着一旦安装了.NET 4.6,无论您如何实例化它,都将始终获得.NET 4.6版本的SqlConnection。 在Visual Studio中构建应用程序时,您将针对特定版本的.NET框架构建,该框架通常位于以下文件夹中:C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework 这意味着在构建msbuild时可以检查您是否使用了您要定位的框 ...