sql左链接怎么用android,左连接到同一个表SQL(Left join to same table SQL)

左连接到同一个表SQL(Left join to same table SQL)

我试图在同一个查询中对同一个表进行左连接,但结果不是okey,我用子查询解决了这个问题,这是错误的查询:

SELECT * FROM TableA ta

LEFT JOIN TableA Lta ON ta.key = Lta.key

AND ta.state IN('C')

AND Lta.state IN ('A','E')

WHERE Lta.key is null

这就是我解决的方式

SELECT * FROM (

SELECT * FROM TableA ta

WHERE ta.state IN('C')

) AS T LEFT JOIN TableA Lta ON T.key = Lta.key

AND Lta.state in ('A','E')

WHERE Lta.key IS NULL

如果您能给我一些与此主题相关的信息,我会对这些疑问感到困惑,我将非常感谢您

谢谢

I am trying to make a left join to the same table in the same query but the result is not okey, I resolved the problem with a subquery this is the wrong query:

SELECT * FROM TableA ta

LEFT JOIN TableA Lta ON ta.key = Lta.key

AND ta.state IN('C')

AND Lta.state IN ('A','E')

WHERE Lta.key is null

This is the way how I resolved

SELECT * FROM (

SELECT * FROM TableA ta

WHERE ta.state IN('C')

) AS T LEFT JOIN TableA Lta ON T.key = Lta.key

AND Lta.state in ('A','E')

WHERE Lta.key IS NULL

I am a little confused with those queries if you can give me some information related to this topic I will be so grateful to you

Thank you

原文:https://stackoverflow.com/questions/35849396

2019-06-17 02:42

满意答案

您在第一次查询时非常接近。 将“ta.state”移动到where子句。 连接是两个表的关系,但是次要标准就是“lta”别名。

SELECT

*

FROM

TableA ta

LEFT JOIN TableA Lta

ON ta.key = Lta.key

AND Lta.state IN ('A','E')

WHERE

ta.state IN('C')

AND Lta.key is null

所以你的主要标准是ta.state是“C”的地方,但是只有当lta的第二个(左连接)别名中的“A”和“E”实例不匹配时

You were very close in your first query. Move the "ta.state" to the where clause. The join is how the two tables relate but secondary criteria on JUST the "lta" alias.

SELECT

*

FROM

TableA ta

LEFT JOIN TableA Lta

ON ta.key = Lta.key

AND Lta.state IN ('A','E')

WHERE

ta.state IN('C')

AND Lta.key is null

So your primary criteria is WHERE the ta.state is "C", but then only if there is NOT a match for the "A" and "E" instances in the second (left-join) alias of lta

相关问答

您在第一次查询时非常接近。 将“ta.state”移动到where子句。 连接是两个表的关系,但是次要标准就是“lta”别名。 SELECT

*

FROM

TableA ta

LEFT JOIN TableA Lta

ON ta.key = Lta.key

AND Lta.state IN ('A','E')

WHERE

ta.state IN('C')

A...

要从Payroll中获取所有在EmpMasterPayroll中没有条目的条目,这应该有效: from p in dcPayroll.Payroll

where p.MasterPayroll == null

select p;

我在这里假设你有两个表之间的linq到sql关联,子表名为“MasterPayroll”。 替代方案: from p in dcPayroll.Payroll

where !(from mp in dcPayroll.MasterPayroll select mp.pa...

希望你在错误的地方分配了AS TOTAL_LINES表别名。 在第二个子查询后放置表别名将解决您的问题。 你可以尝试下面的查询: SELECT *

FROM (

SELECT *

FROM TRN_IN.COIT AS TRANSMISSIONS

LEFT JOIN (

SELECT TRNNumber

,COUNT(ID) AS CountDetails

FROM TRN_IN.COIT

WHERE...

public IQueryable GetProducts(int productID)

{

var products =

from p in this.Products

join c in this.ProductCategoryProducts

on p.CategoryID equals c.ProductCategoryID into pclj

from pc in pclj.DefaultIfEmpty()

...

SLICK 0.11.2适用于此用例。 为此我将我的项目迁移到scala 2.10 / play 2.1 SLICK 0.11.2 works with this use case. I migrated my project to scala 2.10/play 2.1 for this

SELECT t.Type, count(d.Type), sum(d.cost)

FROM Types t LEFT JOIN Details d ON t.Type=d.Type

group by t.Type,d.Type

SELECT t.Type, count(d.Type), sum(d.cost)

FROM Types t LEFT JOIN Details d ON t.Type=d.Type

group by t.Type,d.Type

将LEFT JOIN更改为FULL OUTER JOIN,调整WHERE子句并让我们知道它是如何进行的。 SELECT

record.student_name,

coalesce(record.student_id, attendance.student_number),

record.student_finger,

record.student_section,

record.activity_type,

record.activity_titl...

SELECT

t1.id,

(SELECT COUNT(*) FROM t2 WHERE t2.id = t1.id) as t2_count

FROM t1

SELECT

t1.id,

(SELECT COUNT(*) FROM t2 WHERE t2.id = t1.id) as t2_count

FROM t1

查询中很少有错误,使用[Order]的语法在mysql中无效,然后您需要内部查询的别名。 OrderItem也需要先与Order一起加入。 此外,不需要使用用于子查询的联接,因为您没有执行任何聚合部分来从Item获取数据。 在MySQL中,查询如下所示。 SELECT

h.Name,

i.Type,

oi.Quantity

FROM Hospital h

LEFT JOIN `Order` o ON o.HospitalID = h.HospitalID

INNER JOIN Order...

你必须移动谓词 C.OrderRate != 0 AND

C.OrderQuantity != 0

从WHERE到ON子句: SELECT A.ItemID, A.MSRP, A.SalesPrice, A.Cost, A.DiscountPercent,

B.QuantityOnHand, B.QuantityAvailable, C.OrderRate, C.OrderQuantity

FROM item_info A

LEFT JOIN inventory_status ...

相关文章

CROSS-DOCUMENT JOINS solr 的join相当于SQL的nested join;s

...

有表格如下: t_table 8 想得到这样的结果:(只取有重复的第一个,相同的排除,例如f) 1 a

...

作用: 描述具体的表规则 属性: name – 声明 table 名字,当命中 sql 中的 tabl

...

SELECT a.type, b.postnature, b.compcode FROM 职工岗位管

...

原来的系统性能慢,今天在做性能调优,发现有一个多表查询存在性能问题。 我的hbm.xml配置文件

...

datajoin包在Hadoop的contrib目录下,我们也可以在src下面看见其源码,它的源码很小

...

DDL Operations 创建表: hive> CREATE TABLE pokes (fo

...

转自:http://www.cnblogs.com/Amaranthus/archive/2011/0

...

锋利的SQL的内容摘要:内容简介  本书从基础、开发、性能调整和实战4个方面介绍了sql技术及其应用,

...

最新问答

List lc = driver.findElements(By.cssSelector("table[id*='filter']")); for (WebElement row : lc) { List images = row.findElements(By.tagName("img")); for (WebElement image : images) { image.click(); } } List

我没有任何问题,但我能够通过启用我的弹出窗口拦截器(我使用更好的弹出窗口阻止程序 - Chrome网上应用店 )来重现你在运行Chrome 21.0.1180.89的Windows 7上遇到的问题。 如果您使用弹出窗口阻止程序,请尝试为jsfiddle /您正在使用的站点禁用它。 I didn't have any issues with it, but I was able to reproduce the problem you were having on Windows 7 runnin

opencv已经有开源的人脸识别的代码了,只需要安装一下,有训练好的关于人脸的xml文件,然后根据这两个xml文件,输入一张带有人脸的图片进行检测就好了。参考网址:http://www.cnblogs.com/mengdd/archive/2012/08/01/2619043.html 这里说的更详细一些。matlab是专门针对图像处理的,不过一般的用matlab实现的,用opencv也都可以做的到。有些时候将matlab代码转为opencv还是需要一定时间和一定功底的

您需要使用ProximitySensor来检测手机屏幕何时被覆盖。 这是一个例子: 在android中使用接近传感器 You need to use ProximitySensor to detect when the phone screen is covered. Here is an example: Using proximity sensor in android

我认为找到这个的最简单方法是搜索ProjectName列。 它似乎包含层次结构信息: select c.* from content c where ProjectName+' ' like '%Project 1 %' 额外的空间是确保Project 1与Project 10不匹配。 I found the way to solve. But the actual solution is given by Jayvee. Sorry I didnt know the method it ca

弄清楚了! 它被链接到: searchText: 'Search for a member...', 这将自动填充搜索栏的内容,并尝试根据该搜索词找到用户。 删除此属性解决了这个问题。 Figured it out! It was linked to: searchText: 'Search for a member...', This will autofill the search bar with content and will attempt to find the user

错误2245也可能是密码历史记录问题。 新密码是最近使用的密码吗? 编辑:看起来这个功能在Server 2003 SP 2之后破了。我在使用文档中的示例从C ++调用函数时遇到了同样的错误。 您可能需要使用NetUserSetInfo。 Error 2245 could also be a password history problem. Is the new password one that was used in the recent past? Edit: It looks like

我在网上搜索了很多,为我的问题找到答案。 我花了很多时间,所以我在这里贴出来帮助别人。 为了使GLEW与MinGW一起工作,您应该从GLEW网站下载源代码并放置 来自MinGW \ bin的gcc.exe 来自MinGW32 \ mingw32 \ bin的ar.exe 到GLEWs源文件夹并在该文件夹中创建并运行.bat,如下所示: gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.

使用模板成员函数时,您需要使用template关键字,如下所示: my_postoffice.template get_postbox() 和 po.template get_postbox() cf here: http : //ideone.com/W0owY1代码和这里: 我在哪里以及为什么要放置“template”和“typename”关键字? 有关何时使用模板关键字的确切说明 You need to use the template keyword when using

你不能,至少在Devel :: REPL调用Data :: Dump :: Streamer的情况下。 DDS将始终编码不在\ x20- \ x7e范围内的任何字符。 您可以修改DDS以选择其他方式。 After reading the source of DDS, I came up with this patch based on the Perl Monks code: $ cat quote.rc { no warnings 'redefine'; sub Data::D

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值