2.7 KiB
2.7 KiB
数据库
#1 创建表
CREATE TABLE t_family(
fno INT(11) PRIMARY KEY AUTO_INCREMENT,
eno INT(11) NOT NULL COMMENT '职工编号',
ename VARCHAR(255) NOT NULL COMMENT '职工姓名',
faname VARCHAR(255),
moname VARCHAR(255)
);
#2 添加字段
ALTER TABLE t_salary ADD grade VARCHAR(255) COMMENT '评级';
#3 修改字段数据类型
ALTER TABLE t_employee MODIFY sex ENUM('男', '女');
#4 更新记录
UPDATE t_department d
SET d.tel = '128'
WHERE d.dname = '法务部';
#5 条件、排序查询
SELECT e.ename, e.sex, e.birthday
FROM t_employee e
WHERE e.birthday >= '2000-1-1'
ORDER BY e.birthday DESC;
#6 分组、多表连接查询
SELECT d.dname, SUM(s.basepay+s.overtime+s.allowance+s.insurance)
FROM t_department d, t_employee e, t_salary s
WHERE e.dno = d.dno AND e.eno = s.eno
GROUP BY d.dno;
#7 分组+排序 视图
CREATE VIEW v_jobcount AS
SELECT j.jobtitle, COUNT(*)
FROM t_job j, t_employee e
WHERE j.jno = e.jobno
GROUP BY j.jno
ORDER BY 2;
#8 触发器
CREATE TRIGGER tri_updateGrade
BEFORE UPDATE ON t_salary FOR EACH ROW
BEGIN
IF NEW.basepay < 6000 THEN
SET NEW.grade = 'C';
ELSEIF NEW.basepay < 8000 THEN
SET NEW.grade = 'B';
ELSEIF NEW.basepay >= 8000 THEN
SET NEW.grade = 'A';
END IF;
END;
#9 存储过程
CREATE PROCEDURE `pro_getDepartmentTel`(in `in_dno` int, OUT dept_phone VARCHAR(100))
BEGIN
SELECT CONCAT('部门名称-', dname, ',电话-', tel) INTO dept_phone
FROM t_department
WHERE dno = `in_dno` limit 1;
IF dept_phone IS NULL THEN
SET dept_phone = '没有找到相应的部门';
END IF;
END
C语言-1
/*---------------------------------------------------------
【程序设计】输入n个整数,以-1结束,求所输入的整数中,十位是奇数的所有整数之和。
例1:
输入n个整数,求十位为奇数的数之和(输入-1结束):
10 15 20 25 30 40 50 -1
十位为奇数的数之和为: 105
例2:
输入n个整数,求十位为奇数的数之和(输入-1结束):
8 18 28 -38 48 58 -1 98
十位为奇数的数之和为: 38
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
Program-End之间填入若干语句。不要删除标志否则不得分。
---------------------------------------------------------*/
#include <stdio.h>
int main() {
int num,tenDigit;
int sum = 0,i;
printf("输入n个整数,求十位为奇数的数之和(输入-1结束):\n");
while (1)
{
scanf("%d", &num);
/**********Program**********/
if(num == -1){
break;
}
if((num<0?num*-1:num)%100/10%2==1){
sum += num;
}
/********** End **********/
}
printf("十位为奇数的数之和为: %d\n", sum);
}