我有一张table pub
,如下表所示:
+------------+----------------------------------+
| pub_id | pub_name |
+------------+----------------------------------+
| P0010101 | Jex Max Publication |
| P0020101 | BPP Publication |
| H0030102 | New Harrold Publication |
| H0040101 | Ultra Press Inc. |
| P0050101 | Mountain Publication |
| P0060103 | Summer Night Publication |
| P0070104 | Pieterson Grp. of Publishers |
| P0080102 | Novel Publisher Ltd. |
+--------+--------------------------------------+
我想过滤 AND
子句where if在列中 pub_id
包含 P0
在第一至第二个字母和 0101
在整个句子的第3到第6个字母处。
我试过:
SELECT pub_id, pub_name FROM pub WHERE LEFT(pub_id,2) = 'P0' and pub_id LIKE '%0101%'
但结果是这样的
+------------+----------------------------------+
| pub_id | pub_name |
+------------+----------------------------------+
| P0010101 | Jex Max Publication |
| P0020101 | BPP Publication |
| P0050101 | Mountain Publication |
+--------+--------------------------------------+
我对结果的预期如下:
+------------+----------------------------------+
| pub_id | pub_name |
+------------+----------------------------------+
| P0010101 | Jex Max Publication |
+------------+----------------------------------+
1条答案
按热度按时间00jrzges1#
你可以用
pub_id LIKE 'P00101%'
. 你不需要left()
那么。文件
LIKE