开发者

SQL query error or what it can be?

开发者 https://www.devze.com 2023-01-06 13:54 出处:网络
sitizen(id_citizen,name,sname,age,id_city) i try do query select a.name_city,b.name,b.age from city a,citizen b where a.id_city = b.id_city and

sitizen(id_citizen,name,sname,age,id_city)

i try do query

select a.name_city,b.name,b.age from city a,citizen b where a.id_city = b.id_city and
b.name = 'DAVE' order by b.age desc

expect result like this

 - NY | DAVE | 65

 - NY | DAVE | 12

 - NY | DAVE | 3

but see result what i can't anderstand

 - NY | DAVE | 65

 - NY | DAVE | 3

 - NY | DAVE | 12

if i change desc on ask in query result not better

 - NY | DAVE | 12

 - NY | DAVE | 3

 - NY | DAVE | 65

how it can be ?the age is(int)

another names with this query work fine but not all

CREATE TABLE tz.citizen(
  id_citizen INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  sname VARCHAR(255) NOT NULL,
  age VARCHAR(255) NOT NULL,
  id_sity INT(11) NOT NULL,
  PRIMARY KEY (id_citizen)
)开发者_运维问答
ENGINE = INNODB
AUTO_INCREMENT = 5
AVG_ROW_LENGTH = 4096
CHARACTER SET latin1

COLLATE latin1_swedish_ci;


It appears that an alphanumeric sorting is being used. This could be because the age field is actually a string type such as varchar and not an integral type as you have stated.

Run SHOW CREATE TABLE citizen to double-check the type and change it to an integral type if necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消