表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 10007Now 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 NULLI 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更多推荐
发布评论