表名:customer_datails
customer_id customer_name
101 Hari prasad
102 Hari
103 prasad
104 Vara Prasad
105 Sri Hari bandaru
106 Raja Shekhara Prasad
我上面有桌子。我想显示CUSTOMER_ID'的名字是'Hari'和'prasad'。但我需要'REGEXP'没有和条件。我尝试了以下查询工作。
Ex 1)
select cistomer_id from customer_details where customer_name LIKE 'Raja' 'Prasad';
o/p: 106
Ex 2)
select cistomer_id from customer_details where customer_name LIKE 'Raja' AND
customer_name LIKE 'Prasad';
O/P: 106.
我需要使用regexp进行上述查询而不使用“和”条件(意味着我不想在Ex2等条件下多次使用customer_name字段)
答案 0 :(得分:0)
使用以下脚本: 从customer_details中选择customer_id,其中first_name in('Raja','Prasad');
答案 1 :(得分:-1)
假设您关心订单,以下查询将起作用:
SELECT customer_id
FROM customer_details
WHERE customer_name LIKE '%Raja%Prasad%';
如果您需要任何顺序,则必须使用RLIKE
:
SELECT customer_id
FROM customer_details
WHERE customer_name RLIKE 'Raja.*Prasad|Prasad.*Raja';
答案 2 :(得分:-1)
这应该这样做:
select customer_id from customer_details where customer_name REGEXP '(.*Raja.*)|(.*Prasad.*)';
这可能对您有所帮助