如何在sql查询中使用4和condition [英] how to use 4 and condition in sql query

查看:214
本文介绍了如何在sql查询中使用4和condition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..我在sql查询中遇到问题..



我的查询是:



hi all .. i m facing a problem in sql query..

my query is:

select b.schname from [17CHILD_D] a inner join SCHMAST b on RIGHT(a.sch_code,6)=RIGHT(b.schcode,6) where a.distt=17 and a.block=01 and b.vcode=001



它不起作用..当我删除最后一个条件然后提取记录..



请给我正确的语法..



请提前帮助谢谢


it's not working .. when i remove last condition then records are fetched..

please give me correct syntax..

please help thanks in advance

推荐答案

语法本身没有问题

虽然JOIN很糟糕但是考虑到了setti正确的主键/外键关系



它不起作用我认为它没有返回任何结果,但它确实返回结果如果你删除和b.vcode = 001



首先 - 为什么前面的零...如果列 vcode distt 是数字然后将其写为
There is nothing wrong with the syntax per se
That JOIN is awful though ... consider setting up a proper primary key / foreign key relationship

By "it's not working" I take it to mean that it is not returning any results, but that it does return results if you remove and b.vcode=001

Firstly - why the preceding zeroes ... if columns vcode and distt are numeric then write this as
where a.distt=17 and a.block=1 and b.vcode=1



但是如果它们是char或varchar,那么就像这样写


However if they are char or varchar then write it like this

where a.distt=17 and a.block='01' and b.vcode='001'





之后,如果您仍未获得结果,那么您的数据就不存在表。运行它没有最后一个条件,但添加vcode到SELECT - 仔细看看结果,你会发现没有任何记录有vcode = 1



After that, if you are still not getting results back then there is no matching data on your table. Run it without that last condition but adding vcode to the SELECT - have a good look at the results, you'll find that none of the records have vcode = 1


Hi Bindash,



请检查列是否有值001或其他内容。

我认为它可能像.001
Hi Bindash,

Hmm pls check the column does have value "001" or something else.
I think it may have be like .001


这篇关于如何在sql查询中使用4和condition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆