SQL初级编程命名

CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
  `createDate` datetime DEFAULT NULL,
  `userName` varchar(20) DEFAULT NULL,
  `pwd` varchar(36) DEFAULT NULL,
  `phone` varchar(11) DEFAULT NULL,
  `age` tinyint(3) unsigned DEFAULT NULL,
  `sex` char(2) DEFAULT '男',
  `introduce` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
CREATE TABLE `result` (
  `rid` int(11) NOT NULL AUTO_INCREMENT COMMENT '成绩编号',
  `testName` varchar(255) DEFAULT NULL COMMENT '测试名称',
  `score` double(4,2) DEFAULT NULL COMMENT '成绩',
  `studentId` int(11) DEFAULT NULL COMMENT '学生id',
  PRIMARY KEY (`rid`),
  KEY `studentId` (`studentId`),
  CONSTRAINT `result_ibfk_1` FOREIGN KEY (`studentId`) REFERENCES `student` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into student values(0,'2024-02-25 10:10:10','赵灵儿','123',
'15612345678',16,'女','逍遥哥哥,你终于找到我了。');
insert into student values(0,'2024-02-25 10:10:10','王语嫣','123',
'15612345678',17,'女','慕容复,我和你不共戴天。');
insert into student values(0,'2024-02-25 10:10:10','龙姑娘','123',
'15612345678',22,'女','我想过过过儿过过的日子。');
insert into student values(0,'2024-02-25 10:10:10','杨过','123',
'15612345678',18,'男','一遇杨过误终身。');
insert into student values(0,'2024-02-25 10:10:10','杨逍','123',
'15612345678',27,'男','杨过跟程英的大儿子。');
insert into student (userName,age,introduce)values('黄衣女子',26,'杨过与龙姑娘的大女儿。');
 
insert into result values(0,'政治',96,1);
insert into result values(0,'地理',86,5);
insert into result values(0,'政治',77,3);
insert into result values(0,'英语',99,3);
insert into result values(0,'历史',22,6);
insert into result values(0,'化学',69,2);
insert into result values(0,'Java',79,5);
insert into result values(0,'Java',67,6);
insert into result values(0,'政治',97,2);
insert into result values(0,'物理',76,6);
insert into result values(0,'物理',82,2);
insert into result values(0,'化学',56,4);

2dml

set @userName1='地狱火牛战士',@userName2='地狱火马战士',@userName3='地狱火牛马';
select @userName1,@userName2,@userName3;
#标识符命名规范 开头只可以用大小写英文字母,下划线
#符号(:=)查看并赋值,否则就是只会赋值
set @userName4='大聪明';
set @userName5:='卧龙凤雏';
select @userName4,@userName5;

3计算

set@x=1,@y=6,@dx=0.2,@dy=0.1;
select@x + @y;
select@x - @y;
select@x * @y;
select@x / @y;
select@x % @y;
set @result1=@dx + @dy;
set @result2=@dx - @dy;
set @result3=@dx * @dy;
set @result4=@dx / @dy;
set @result5=@dx % @dy;
select @result1,@result2,@result3,@result4,@result5;
select round(select @dx / @dy,2);

4运算符

set@x=1,@y=6;
#关系运算返回的是0与1,其中0时FALSE,1代表AND(&)OR(|)
select@x <= @y;
select@x > @y;
select@x = @y;
select TRUE AND TRUE;
select FALSE OR TRUE;

5变量在SQL中的运用

et @userName='地狱火';
set @age='100';
select*from student where userName=@userName or age=@age;
set @userName1='地狱火';
set @userName2='da';
select*from student where userName in(@userName1,@userName2);

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值