SQL查询-如何不包括一些结果 [英] SQL Query - How to not include some results

查看:126
本文介绍了SQL查询-如何不包括一些结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,在我无法正确形式化之前提出此问题。我在表中有一个代码列,想要查询它,但是要删除带有某些特定代码的某些元素。假设我想使用代码从4开始的元素,但不包括代码的第六个数字为9(1121290)的元素。

I apologize if this question was asked before I just couldn't correctly formalize it. I have a code column in a table and want to query it but remove some elements with some particular code. Say I want to take elements with code starting from 4 but not include the elements with code whose 6-th number is 9 (1121290).

代码列包含字符串最大长度为8个字符的数字。并且我想接受几乎所有以4开头的内容,除了以411、427和428开头的元素

The code column contains string of numbers with max-length of 8 char. and I want to take almost everything that starts with 4 except elements that start with 411, 427 and 428

推荐答案

是的这样的查询:-

我有6位数字代码的列元素。

I have column element with 6 digit codes.

我正在获取其元素第一个数字是4或第六个数字是9。

I am fetching element whose 1st digit is 4 or 6th is 9.

我们必须使用 _

we have to use % and _ for fetching..

SELECT element  FROM "table" WHERE element LIKE '%4____9%';

尝试它会起作用。

以4开头的所有内容,但以411、427和428开头的元素除外:-

Everything that starts with 4 except elements that start with 411, 427 and 428 :-

 SELECT element  FROM "table" WHERE element LIKE '%4__';

第一个数字是4,第六个数字不是9:我测试了这个数字,它工作正常,请尝试以下操作: -

1st digit is 4 and 6th is not 9: I tested this one it is working fine try this :-

SELECT element  
FROM "table" 
WHERE element NOT LIKE '%_____9' and element LIKE '%4_____'

这篇关于SQL查询-如何不包括一些结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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