首页 >> 基础教程
mysql的helloworld
一、创建数据库
create database testdb COLLATE "utf8_general_ci";
二、创建表格
CREATE TABLE `user` ( `id` int(11) AUTO_INCREMENT comment "自增id", `user_code` varchar(255) comment "用户编码", `user_name` varchar(255) comment "用户名称", `age` int(11) comment "年龄", `money` DECIMAL(10,2) comment "拥有资金", PRIMARY KEY(`id`)) ENGINE=InnoDB charset="utf8"; CREATE TABLE `user_car` ( `user_code` varchar(255) comment "用户编码", `car_name` varchar(255) comment "用户名称") ENGINE=InnoDB charset="utf8";
三、 插入数据
insert into user values("no1", "小东",39); insert into user values("no2", "小明",60); insert into user_car values("no1", "法拉第"); insert into user_car values("no1", "保时捷"); insert into user_car values("no2", "保时捷");
四、查询数据
1、我已经知道一个用户code=no1,请问他的名字年龄分别是多少?
select user_name, age from user where user_code="no1";
2、用户中有个人是60岁,他是谁?
select user_name from user where age=60;
3、60岁的那个用户,他的车是什么车?
select car_name from user_car where user_code=(select user_code from user where age=60);
最新文章
InnoDB 和 MyISAM 主要有什么区别?2025-07-06
mysql存储引擎应该怎么选择?2025-07-06
mysql的几种存储引擎2025-07-06
MySQL 的段区页行2025-07-06
一条更新语句是如何执行的?2025-07-06
mysql中一条查询语句是如何执行的?2025-07-02
MySQL基础架构及执行流程解析2025-07-02
MySQL SQL语法树解析过程详解2025-07-02
mysql中SQL 的隐式数据类型转换?2025-07-01
MySQL 第 3-10 条记录怎么查?2025-06-30