In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
The purpose of this article is to share with you about the use of "where 1" in SQL. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The use of where 1 / 1 in SQL
Explanation:
In fact, 1x1 is permanent, meaning unconditional, that is to say, it doesn't matter whether you have it or not in the SQL statement.
This 1q1 is often used when applications piece together where conditions according to different user choices.
For example, the web interface queries the user's information, and where defaults to 1: 1, so that even if the user does not select any conditions, the sql query will not make an error. If the user chooses a name, then where becomes where 1 name 1 and name = 'name entered by the user', and if other conditions are selected, just keep appending and statements to the where condition.
If you don't need 1: 1, every additional condition, you have to judge whether there is a where condition or not, and if not, write where. Write and statements as soon as you have them, so you can simplify the complexity of your application by using 1x1 at this time.
Example:
As in the following code, $where='1 is defined first, and then you don't have to determine whether $where exists or not.
Public function listAction () {$get = $this- > getQuery (); $statementBalanceDetailModel = M ('Ticket\ StatementBalanceDetail'); $page = isset ($get [' page'])? Intval ($get ['page']): 1; $pageSize = isset ($get [' page_size'])? Intval ($get ['page_size']): 10; / / usefulness $where =' 1room1'; $binds = array (); if (isset ($get ['id']) & & $get [' id']! =') {$where. = 'and id =: id'; $binds [' id'] = trim ($get ['id']) } if (isset ($get ['shop_name']) & & $get [' shop_name']! ='') {$where. = 'and shop_name =: shop_name'; $binds [' shop_name'] = trim ($get ['shop_name']) } if (isset ($get ['statement_sn']) & & $get [' statement_sn']! ='') {$where. = 'and statement_sn =: statement_sn'; $binds [' statement_sn'] = trim ($get ['statement_sn']);} $where. =' order by id desc' $result = $statementBalanceDetailModel- > paginate ($where, $pageSize, $page, $fields = array (), $binds); $sceneryList = $result ['data']; $total = $result [' total_result']; $pager = Paginate::web ($total, $page, $pageSize); $data = array ('pager' = > $pager,' sceneryList' = > $sceneryList,); $this- > getView ()-> assign ($data) } Thank you for reading! This is the end of this article on the usage of "where 1 in SQL". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.