Can the truncated string be treated as a where condition directly in SQL discourse?

Source: Internet
Author: User
Whether the intercepted string can be treated directly as a where condition in the SQL statement
For example, this
Select ' id ' from ' table ' where left (' flag ', 1) = 1;


I have a list of flags named flag used to represent various attributes of the commodity, 10-digit int, for example 1100000000.
Then for example the first number 1 indicates that the price range of the commodity is 100-200 yuan.
And then I want to pick out the flag from the table and take out the first number of 1 items.
Can this be achieved, just using MySQL mysql

Share to:


------Solution--------------------
Select ' id ' from ' table ' where left (' flag ', 1) = ' 1 '
------Solution--------------------
Your SQL, isn't it??
------Solution--------------------
Performance should be less of a function.
------Solution--------------------

As long as the left side of the matching string like is not a variable, then you can use the index
For 1,2,11, so it's 1,11,2.
Like ' 1% ' is always quick to take out 1, 11, as they gather together
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.