有两个表具有相同类型的记录,在table1中查找table2中未使用的记录[closed](There are two table having same type of records in tha

编程入门 行业动态 更新时间:2024-10-26 06:37:39
有两个表具有相同类型的记录,在table1中查找table2中未使用的记录[closed](There are two table having same type of records in that finding the unused record from table2 in table1 [closed])

表1:Account&Table2:AccountDtl。

帐户表的列为Account_Num。

AccountDtl表的列为Account_value。

Account_Num和Account_value都具有相同类型的值。

例如:

Account_num 10001 10002 10003 10004 Account_value 10001 10002 10003 10004 10005 10006 10007

现在我必须在Account_value(列)中获得(10005,10006,10007)记录。 如何编写SQL查询?

我曾以这种方式尝试过,但没有得到我预期的结果。

从AccountDtl中选择k.Account_value k左外连接帐户a on k.Account_value = a.Account_num;

Table1: Account & Table2: AccountDtl.

Account table having column as Account_Num.

AccountDtl table having column as Account_value.

Both Account_Num and Account_value having same type of values.

For Example:

Account_num 10001 10002 10003 10004 Account_value 10001 10002 10003 10004 10005 10006 10007

Now i have to get (10005, 10006 ,10007) record in Account_value (column). How to write sql query?

I had tried in this way.But didn't get my expected output.

Select k.Account_value from AccountDtl k left outer join Account a on k.Account_value = a.Account_num;

最满意答案

认为你在这里想要的是AccountDtl的值和Account的值之间的差异。 这样做的一种方法是,将前一个表与后一个表相对,然后使用NULL来标识要保留的记录。 像这样的东西:

SELECT Account_value FROM AccountDtl a1 LEFT JOIN Account a2 ON a1.Account_value = a2.Account_num WHERE a2.Account_num IS NULL

I think what you want here is the difference between the values in AccountDtl and those in Account. One way of doing this is to LEFT JOIN the former table against the latter and then use NULL to identify records you want to retain. Something like this:

SELECT Account_value FROM AccountDtl a1 LEFT JOIN Account a2 ON a1.Account_value = a2.Account_num WHERE a2.Account_num IS NULL

更多推荐

本文发布于:2023-07-15 21:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中未   类型   有两个   closed   record

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!