简体   繁体   中英

how to get numeric values form sql query

My problem is I have a table in which offers are stored and I want to display only those records who have 50% (the substring '50%' in them).

This is my table Schema: 在此处输入图片说明 An Example record would be:

FLAT 50% Off on Essel world entry tickets and more.
FLAT 50% Off on Rs
2495 & above. US polo - Upto 50% off

How would I go about composing an SQL query to select these? The column name of the field is called coupon_name

Like will do..

 select * from table
    where coupon_name like '%50[%]%'

This will give all records like below one having 250,this can be valid since percentage can't be greater than 100

sakfjfjk50%sfjbsadjkfbjksdf
sakfjfjk250%sfjbsadjkfbjksdf

I you need records containing '50%' you can use:

SELECT *
FROM YourTable
WHERE coupon_name LIKE '%50[%]%'

Or use ESCAPE :

SELECT *
FROM YourTable
WHERE coupon_name LIKE '%50\%%' ESCAPE '\'

Or:

SELECT *
FROM YourTable
WHERE coupon_name LIKE '%50|%%' ESCAPE '|'

The third one should work in MySQL and SQL Server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM