Can the SQL statement directly regard the intercepted string as the where condition MySQL?
For example
Select 'id' from 'table' where left ('flag', 1) = 1;
I have a string named flag used to indicate various attributes of the product, 10-digit Int, such as 1100000000.
For example, the first digit 1 indicates that the commodity price range is between and RMB.
Then I want to find the first item with the number 1 in the flag from the table.
Can this be done? just use mysql
Reply to discussion (solution)
Select 'id' from 'table' where left ('flag', 1) = '1'
Isn't your SQL ??
Dizzy... I felt like I wrote it like this. I tried it a few times but it didn't work.
The where condition is incorrect.
In addition, I would like to ask, how is the performance of such SQL statements?
Select 'id' from 'table' where left ('flag', 1) = '1'
How is the performance of such SQL statements?
Function should be used in poor performance.
Performance is not good, because you cannot use index writing to use the index (if any) select 'id' from 'table' where 'flag' like '1%'
You want to filter items. use your method. Have you ever wondered what to do if you want to add attributes to your previous data?
Performance is not good, because you cannot use index writing to use the index (if any) select 'id' from 'table' where 'flag' like '1%'
Is it to add an index to the flag field? is like more efficient than left?
You want to filter items. use your method. Have you ever wondered what to do if you want to add attributes to your previous data?
I am thinking, for example, the product has 10 Attributes. in my flag field, each attribute corresponds to a number. now I only use the first two attributes, and I automatically add 0 to the back, assign values later. Do you have any better classification methods?
Create an attribute table aid attribute
Gid of a commodity table
When both aid and gid in the corresponding edge of the aid gid table can index extended attributes, you only need to edit the attribute table.
As long as the left side of the like matching string is not a variable, the index can be used for 1, 2, and 11. Therefore, after, 2 like '1% ', will always be retrieved quickly, because they are together