0

我有以下值的表

docid dcname doctitle 
1      **aa   **aaa01-01 
2      aa**   aafddg-02**
3      a**a   asds***90-05
4      abcd   abcd-06.

现在在此表中,我想过滤以 ** 开头和结尾的“Doctitles”值

我的结果应该是

dcid docname doctitle
3    a**a    asds***90-05
4    abcd    abcd-06

我正在使用以下查询,但获得的结果只是中间带有 ** 的 Doctitles

SELECT *
  FROM table1
 WHERE     doctitle NOT LIKE '**%'
       AND doctitle NOT LIKE '%**'
       AND doctitle LIKE '%**%'

这只给了我下面的结果 dcid docname doctitle 3 a* a asds **90-05

在这方面需要帮助。

4

6 回答 6

0

SELECT * FROM table1 WHERE doctitle NOT LIKE ' %' OR doctitle NOT LIKE '% '

于 2013-10-28T06:22:09.353 回答
0

尝试不使用and doctitle like '%**%' 您的查询应该看起来select * from table1 where doctitle not like '**%' and doctitle not like '%**'

另一种解决方案:

SELECT * FROM table1 WHERE LEFT(doctitle,2) != '**' AND RIGHT(doctitle,2) != '**'
于 2013-10-28T06:10:39.660 回答
0

尝试以下选项

select * from table1 where doctitle like '**%' and doctitle like '%**'

或者

select * from table1 where doctitle like '**%'
UNION
select * from table1 where doctitle like '%**'

有关更多详细信息,请参阅

于 2013-10-28T06:12:13.823 回答
0

尝试这个..

SELECT  *
FROM    table1
WHERE   doctitle LIKE '%**%'
AND     docid  NOT IN (SELECT docid  FROM tabel1 WHERE doctitle NOT LIKE '**%' )
AND     docid  NOT IN (SELECT docid  FROM tabel1 WHERE doctitle NOT LIKE '%**' )
于 2013-10-28T06:21:26.963 回答
0

我试过了,它奏效了——

select * from 
(
select 
1    docid ,  '**aa' dcname  ,  '**aaa01-01' doctitle 
from dual
union all  
select 
2,      'aa**',   'aafddg-02**'
from dual
union all
select 
3 ,     'a**a' ,  'asds***90-05'
from dual
union all
select 
4  ,    'abcd'  , 'abcd-06.'
from dual
)
where doctitle not like '**%' and doctitle not like '%**'  
于 2013-10-28T06:14:34.897 回答
0

假设您的意思是您希望doctitles 以 s 开头或结尾**,您只需要省略最后一个条件:

SELECT *
FROM   table1
WHERE  doctitle NOT LIKE '**%'
  AND  doctitle NOT LIKE '%**'
于 2013-10-28T06:15:44.463 回答