Query-sorting of mysql Infinitus categories

Source: Internet
Author: User
The table is designed in this way! IMG (img.ask.csdn.netupload201507151436949175_57730.png) 2, 4, 5. Please ignore the fields that you want to query in this format. Level 1 category, level 2 category, Level 3 category, Level 3 category, level 2 category, Level 3 category, Level 3 category, Level 3 category, and Level B. I use select * fromvn_erp_healthpriceorderbysortssor the results of the varchar type query are as follows! [Image description] (img... mysql Query Infinitus classification sorting

The table is designed in this way.

Ignore 2, 4, and 5 fields
Now we need to query the data in this format.
Level 1
Level 2 classification
Level 3 classification
Level 3 classification B
Level 2 classification B
Level 3 classification
Level 3 classification B
The SQL statement I used is select * from vn_erp_healthprice order by sorts.

The sorts field is of the varchar type.
The query result is as follows:

The sorting results meet the business requirements, but why is the sorting result first 1-11 before 1-2?
What's the principle of sorting strings? I haven't used this classification for a long time. I can't think of it for a while.
Please enlighten me

The table SQL is as follows:

/* Navicat MySQL Data TransferSource Server: localhostSource Server Version: 50621 Source Host: 127.0.0.1: 3306 Source Database: testTarget Server Type: MYSQLTarget Server Version: 50621 File Encoding: 65001 Date: 16:38:49 */SET FOREIGN_KEY_CHECKS = 0; -- optimize Table structure for 'vn _ erp_healthprice '-- ---------------------------- drop table if exists 'vn _ erp_healthprice '; create table 'vn _ erp_healthprice' ('id' int (10) not null AUTO_INCREMENT COMMENT 'primary key', 'lyid' varchar (10) not null default ''comment' service item ID', 'name' varchar (100) not null default ''comment' service item name', 'price' varchar (10) not null default ''comment' work hour unit price ', 'hours' varchar (10) not null default ''comment' work hour', 'parent _ id' int (11) not null default '0', 'sorts' varchar (20) not null default ''comment' sort', primary key ('id '), KEY 'hid '('lyid') ENGINE = InnoDB AUTO_INCREMENT = 27 default charset = utf8; -- restore Records of vn_erp_healthprice -- ------------------------ insert into 'vn _ erp_healthprice 'values ('1', '', 'maintenance (primary classification )','','', '0', '1'); insert into 'vn _ erp_healthprice 'values ('2', '', 'change (secondary classification )','','', '1', '1-2'); insert into 'vn _ erp_healthprice' VALUES ('3', '1', 'Oil change ','','', '2', '1-2-3 '); insert into 'vn _ erp_healthprice' VALUES ('4', '2', 'change oil filter ','','', '2', '1-2-4 '); insert into 'vn _ erp_healthprice' VALUES ('5', '3', 'Change air filter ','','', '2', '1-2-5 '); insert into 'vn _ erp_healthprice' VALUES ('6', '4', 'change fuel filter ','','', '2', '1-2-6 '); insert into 'vn _ erp_healthprice' VALUES ('7', '5', 'change all spark plugs ','','', '2', '1-2-7 '); insert into 'vn _ erp_healthprice' VALUES ('8', '6', 'checking power steering oil ','','', '11', '1-2-8 '); insert into 'vn _ erp_healthprice' VALUES ('9', '7', 'change vehicle brake fluid ','','', '2', '1-2-9 '); insert into 'vn _ erp_healthprice' VALUES ('10', '8', 'Check automatic transmission oil ','','', '11', '1-11-10 '); insert into 'vn _ erp_healthprice' VALUES ('11', '', 'Check (secondary classification )','', '', '1', '1-11'); insert into 'vn _ erp_healthprice 'values ('12', '9', 'Check or replace the manual transmission oil ', '','', '11', '1-11-12 '); insert into 'vn _ erp_healthprice 'values ('13', '10 ', 'Check the engine timing belt ', '','', '11', '1-11-13'); insert into 'vn _ erp_healthprice 'values ('14 ', '11', 'Change air conditioner filter', '','', '2', '1-2-14 '); insert into 'vn _ erp_healthprice 'values ('15 ', '', 'Regular (secondary classification) ','', '', '1', '1-15 '); insert into 'vn _ erp_healthprice' VALUES ('16', '12', 'Add media regularly ', '','', '15', '1-15-16 '); insert into 'vn _ erp_healthprice' VALUES ('17', '13', 'Check air conditioning duct ', '','', '11', '1-11-17 '); insert into 'vn _ erp_healthprice' VALUES ('18', '14', 'change antifreeze coolant ', '','', '2', '1-2-18 '); insert into 'vn _ erp_healthprice' VALUES ('19', '15', 'Check the thickness and adjustment. if necessary, replace the front brake pad ', '','', '11 ', '1-11-19 '); insert into 'vn _ erp_healthprice 'values ('20', '16', 'Check thickness, adjust, change front brake disk ','', '', '11', '1-11-20 '); insert into 'vn _ erp_healthprice 'values ('21', '17',' check thickness, adjust, when necessary, replace the rear brake pad (shoe) ', '','', '11', '1-11-21'); insert into 'vn _ erp_healthprice 'values ('22 ', '18', 'Check the thickness and adjustment. after necessary, replace the brake disc (drum) ', '','', '11', '1-11-21 '); insert into 'vn _ erp_healthprice' VALUES ('23', '', 'adjustment (secondary classification) ','', '', '1 ', '1-22'); insert into 'vn _ erp_healthpric' VALUES ('24', '19', 'adjust wiper (wiper )','','', '23', '1-22-23 '); insert into 'vn _ erp_healthprice' VALUES ('25', '20', 'Check batter ','','', '11', '1-11-24 '); insert into 'vn _ erp_healthprice' VALUES ('26', '21', 'Check shock absorber ','','', '11', '1-11-25 ');

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.