热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PostgreSQL14学习笔记_2.1_练习

[目录]这是超经典SQL练习题,做完这些你的SQL就过关了的题目在PostgreSQL14上的解答。创建测试表格创建数据

@[目录]
这是超经典SQL练习题,做完这些你的SQL就过关了的题目在PostgreSQL14上的解答。

创建测试表格

创建数据库

CREATE DATABASE edudb_test;

创建表并插入数据


学生表

CREATE TABLE student(s_id VARCHAR(10),s_name VARCHAR(20),s_age DATE,s_sex CHAR(1)
);
INSERT INTO student(s_id, s_name, s_age, s_sex) VALUES('01' , '赵雷' , '19900101' , '男'),('02' , '钱电' , '19901221' , '男'),('03' , '孙风' , '19900520' , '男'),('04' , '李云' , '19900806' , '男'),('05' , '周梅' , '19911201' , '女'),('06' , '吴兰' , '19920301' , '女'),('07' , '郑竹' , '19890701' , '女'),('08' , '王菊' , '19900120' , '女')
;

科目表

CREATE TABLE course(c_id VARCHAR(10),c_name VARCHAR(20),t_id VARCHAR(10)
);
INSERT INTO course VALUES('01' , '语文' , '02'),('02' , '数学' , '01'),('03' , '英语' , '03')
;

教师表

CREATE TABLE teacher(t_id VARCHAR(10),t_name VARCHAR(20)
);
INSERT INTO teacher VALUES('01' , '张三'),('02' , '李四'),('03' , '王五')
;

成绩表

CREATE TABLE score(s_id VARCHAR(10),c_id VARCHAR(10),sc_score DECIMAL(3,1)
);
INSERT INTO score VALUES('01' , '01' , 80),('01' , '02' , 90),('01' , '03' , 99),('02' , '01' , 70),('02' , '02' , 60),('02' , '03' , 80),('03' , '01' , 80),('03' , '02' , 80),('03' , '03' , 80),('04' , '01' , 50),('04' , '02' , 30),('04' , '03' , 20),('05' , '01' , 76),('05' , '02' , 87),('06' , '01' , 31),('06' , '03' , 34),('07' , '02' , 89),('07' , '03' , 98)
;

50道练习题


1. 查询" 01 “课程比” 02 "课程成绩高的学生的信息及课程分数

SELECT st.*, sc1.sc_score FROM student AS st INNER JOIN score AS sc1 ON st.s_id = sc1.s_idWHERE c_id = '02' AND sc1.sc_score > (SELECT sc2.sc_score FROM score AS sc2 WHERE c_id='01' AND sc1.s_id = sc2.s_id);
/*原博主的方法*/
SELECT sc1.*, sc2.c_id, sc2.sc_score
FROM (SELECT * FROM score WHERE c_id='01') AS sc1
LEFT JOIN
(SELECT * FROM score WHERE c_id='02') AS sc2
ON sc1.s_id = sc2.s_id
WHERE sc1.sc_score > sc2.sc_score;

1.1 查询同时存在" 01 “课程和” 02 "课程的情况

SELECT sc1.*, sc2.c_id, sc2.sc_score
FROM (SELECT * FROM score WHERE c_id='01') AS sc1
INNER JOIN
(SELECT * FROM score WHERE c_id='02') AS sc2
ON sc1.s_id = sc2.s_id;

1.2 查询存在" 01 “课程但可能不存在” 02 "课程的情况(不存在时显示为 null )

SELECT sc1.*, sc2.c_id, sc2.sc_score
FROM (SELECT * FROM score WHERE c_id='01') AS sc1
LEFT JOIN
(SELECT * FROM score WHERE c_id='02') AS sc2
ON sc1.s_id = sc2.s_id;

1.3 查询不存在" 01 “课程但存在” 02 "课程的情况

SELECT sc2.*
FROM (SELECT * FROM score WHERE c_id='01') AS sc1
RIGHT JOIN
(SELECT * FROM score WHERE c_id='02') AS sc2
ON sc1.s_id = sc2.s_id
WHERE sc1.sc_score is null;
/*原博主的方法*/
SELECT sc2.*
FROM score AS sc2
WHERE sc2.c_id = '02' and sc2.s_id not in (SELECT s_id FROM score WHERE c_id = '01');

2. 查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩

SELECT st.s_id, st.s_name, sc.avg_score FROM student AS st INNER JOIN (SELECT s_id, AVG(sc_score) AS avg_score FROM score GROUP BY s_id) AS sc ON st.s_id = sc.s_idWHERE sc.avg_score >= 60;

3. 查询在 SC 表存在成绩的学生信息

SELECT st.*FROM student AS st INNER JOIN (SELECT DISTINCT s_id FROM score) AS sc ON st.s_id = sc.s_id;
/*原博主的方法
因为没有连接查询,原博主的效率更高。*/
SELECT * FROM student WHERE s_id in (SELECT DISTINCT s_id FROM score);

4. 查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩(没成绩的显示为 null )

SELECT st.s_id, st.s_name, sc.course_count, sc.sum_scoreFROM student AS st LEFT JOIN (SELECT s_id, count(c_id) AS course_count, sum(sc_score) as sum_score FROM score GROUP BY s_id) AS sc ON st.s_id = sc.s_id;

4.1 查有成绩的学生信息

SELECT st.*FROM student AS st INNER JOIN (SELECT DISTINCT s_id FROM score) AS sc ON st.s_id = sc.s_id;

5. 查询「李」姓老师的数量

SELECT count(t_id) FROM teacher WHERE t_name like '李%';

6. 查询学过「张三」老师授课的同学的信息

SELECT st.* FROM student AS st LEFT JOIN score AS sc ON st.s_id = sc.s_id WHERE sc.c_id = (SELECT c_id FROM course WHERE t_id = (SELECT t_id FROM teacher WHERE t_name = '张三'))
;
/*原博主的方法*/
SELECT * FROM student WHERE s_id in (SELECT DISTINCT s_id FROM scoreWHERE c_id = (SELECT c_id FROM Course WHERE t_id = (SELECT t_id FROM teacherWHERE t_name = '张三'))
);

7. 查询没有学全所有课程的同学的信息

/*这里添加了IS NULL的条件。如果删除此条件,则不会显示一门课没考的同学信息*/
SELECT st.*, course_count FROM student AS st LEFT JOIN (SELECT s_id, count(c_id) AS course_count FROM score GROUP BY s_id) AS sc ON st.s_id &#61; sc.s_id WHERE sc.course_count<3 OR sc.course_count IS NULL
;
/*原博主的方法*/
SELECT * FROM student WHERE s_id IN (SELECT s_id FROM scoreGROUP BY s_id HAVING count(c_id)<3
);
SELECT * FROM student WHERE s_id NOT IN (SELECT s_id FROM scoreGROUP BY s_id HAVING count(c_id)&#61;3
);

8. 查询至少有一门课与学号为" 01 "的同学所学相同的同学的信息

SELECT st.* FROM student AS st INNER JOIN (SELECT DISTINCT s_id FROM score WHERE c_id IN (SELECT c_id FROM score WHERE s_id&#61;&#39;01&#39;) AND s_id!&#61;&#39;01&#39;) AS sc ON st.s_id &#61; sc.s_id
;
/*原博主的方法*/
SELECT * FROM student WHERE s_id IN (SELECT s_id FROM scoreWHERE c_id in (SELECT DISTINCT c_id FROM score WHERE s_id&#61;&#39;01&#39;)AND s_id!&#61;&#39;01&#39;
);

9. 查询和" 01 "号的同学学习的课程完全相同的其他同学的信息

SELECT st.* FROM student AS st INNER JOIN (SELECT s_id, count(c_id) AS count_c_id FROM score GROUP BY s_id) AS scON st.s_id &#61; sc.s_idWHERE sc.count_c_id &#61; (SELECT count(c_id) FROM score WHERE s_id&#61;&#39;01&#39;)
;
/*原博主的方法*/
SELECT * FROM studentWHERE s_id IN (SELECT s_id FROM score GROUP BY s_id HAVING count(c_id)&#61;(SELECT count(c_id) FROM score WHERE s_id&#61;&#39;01&#39;));

10. 查询没学过"张三"老师讲授的任一门课程的学生姓名

SELECT st.* FROM student AS stWHERE st.s_id NOT IN (SELECT s_id FROM score WHERE c_id IN (SELECT c_id FROM course WHERE t_id &#61; (SELECT t_id FROM teacher WHERE t_name &#61; &#39;张三&#39;)));
;

11. 查询两门及其以上不及格课程的同学的学号&#xff0c;姓名及其平均成绩

SELECT st.s_id, st.s_name, sc.avg_sc FROM student AS st INNER JOIN (SELECT DISTINCT s_id, count(sc_score) AS count_sc, avg(sc_score) AS avg_sc FROM score GROUP BY s_id) AS sc ON st.s_id &#61; sc.s_id WHERE sc.count_sc >&#61;2 AND sc.avg_sc <60
;

12. 检索" 01 "课程分数小于 60&#xff0c;按分数降序排列的学生信息

SELECT st.s_id, st.s_name, sc.sc_score
FROM student AS st
RIGHT JOIN score AS sc
ON st.s_id&#61;sc.s_id
WHERE sc.c_id&#61;&#39;01&#39; AND sc.sc_score <60
ORDER BY sc.sc_score DESC;

13. 按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩

SELECT st.* FROM student AS st LEFT JOIN (SELECT s_id, sc_score FROM score WHERE c_id&#61;&#39;01&#39;) AS sc ON st.s_id &#61; sc.s_id WHERE sc.sc_score<60 ORDER BY sc.sc_score DESC
;

14. 查询各科成绩最高分、最低分和平均分&#xff1a;

以如下形式显示&#xff1a;课程 ID&#xff0c;课程 name&#xff0c;最高分&#xff0c;最低分&#xff0c;平均分&#xff0c;及格率&#xff0c;中等率&#xff0c;优良率&#xff0c;优秀率
及格为>&#61;60&#xff0c;中等为&#xff1a;70-80&#xff0c;优良为&#xff1a;80-90&#xff0c;优秀为&#xff1a;>&#61;90
要求输出课程号和选修人数&#xff0c;查询结果按人数降序排列&#xff0c;若人数相同&#xff0c;按课程号升序排列

WITH RECURSIVE sc1(c_id, score, jige, zhongdeng, youliang,youxiu) AS (
SELECT c_id, sc_score, CASE WHEN sc_score>&#61;60 THEN 1 ELSE 0 END AS jige, CASE WHEN sc_score>&#61;70 THEN 1 ELSE 0 END AS zhongdeng,CASE WHEN sc_score>&#61;80 THEN 1 ELSE 0 END AS youliang,CASE WHEN sc_score>&#61;90 THEN 1 ELSE 0 END AS youxiuFROM score
)
SELECT c_id, count(score), max(score) AS max_sc, min(score) AS min_sc, round(avg(score),2) AS avg_sc, round(avg(jige)*100,2) AS per_jige,round(avg(zhongdeng)*100,2) AS per_zhongdeng,round(avg(youliang)*100,2) AS per_youliang,round(avg(youxiu)*100,2) AS per_youxiugFROM sc1 GROUP BY c_idORDER BY count(score) DESC, c_id
;

15. 按各科成绩进行排序&#xff0c;并显示排名&#xff0c; Score 重复时保留名次空缺

SELECT st.s_id, st.s_name, RANK() OVER(ORDER BY sc_score DESC) AS rank1, sc.sc_score
FROM (SELECT s_id, sc_score FROM score WHERE c_id&#61;&#39;01&#39;) AS sc INNER JOIN student AS st
ON sc.s_id&#61;st.s_id
;

15.1 按各科成绩进行排序&#xff0c;并显示排名&#xff0c; Score 重复时合并名次

SELECT st.s_id, st.s_name, DENSE_RANK() OVER(ORDER BY sc_score DESC) AS rank1, sc.sc_score
FROM (SELECT s_id, sc_score FROM score WHERE c_id&#61;&#39;01&#39;) AS sc INNER JOIN student AS st
ON sc.s_id&#61;st.s_id
;

16. 查询学生的总成绩&#xff0c;并进行排名&#xff0c;总分重复时保留名次空缺

SELECT st.s_id, st.s_name, RANK() OVER(ORDER BY sum_score DESC) AS rank1, sc.sum_score
FROM (SELECT s_id, sum(sc_score) AS sum_scoreFROM score GROUP BY s_id) AS sc INNER JOIN student AS st
ON sc.s_id&#61;st.s_id;

16.1 查询学生的总成绩&#xff0c;并进行排名&#xff0c;总分重复时不保留名次空缺

SELECT st.s_id, st.s_name, DENSE_RANK() OVER(ORDER BY sum_score DESC) AS rank1, sc.sum_score
FROM (SELECT s_id, sum(sc_score) AS sum_scoreFROM score GROUP BY s_id) AS sc INNER JOIN student AS st
ON sc.s_id&#61;st.s_id;

17. 统计各科成绩各分数段人数&#xff1a;课程编号&#xff0c;课程名称&#xff0c;[100-85]&#xff0c;[85-70]&#xff0c;[70-60]&#xff0c;[60-0] 及所占百分比

注&#xff1a;题干中分数段[100-85]用的是闭区间&#xff0c;会导致85、70和60被重复计算。
所以改为半开区间&#xff08;100-85]&#xff0c;&#xff08;85-70]&#xff0c;&#xff08;70-60]&#xff0c;&#xff08;60-0]。

WITH RECURSIVE sc1(c_id, score) AS (
SELECT c_id, sc_score, CASE WHEN sc_score<60 THEN 1 ELSE 0 END AS scale1, CASE WHEN sc_score>&#61;60 AND sc_score<70 THEN 1 ELSE 0 END AS scale2,CASE WHEN sc_score>&#61;70 AND sc_score<85 THEN 1 ELSE 0 END AS scale3,CASE WHEN sc_score>&#61;85 THEN 1 ELSE 0 END AS scale4FROM score
)
SELECT sc1.c_id, course.c_name,sum(sc1.scale1) AS scale1, sum(sc1.scale2) AS scale2, sum(sc1.scale3) AS scale3, sum(sc1.scale4) AS scale4, round(avg(scale1)*100,2) AS per_scale1,round(avg(scale2)*100,2) AS per_scale2,round(avg(scale3)*100,2) AS per_scale3,round(avg(scale4)*100,2) AS per_scale4FROM sc1 INNER JOIN course ON sc1.c_id&#61;course.c_idGROUP BY sc1.c_id, course.c_name
;

18. 查询各科成绩前三名的记录

SELECT * FROM (SELECT *, RANK() OVER(PARTITION BY c_id order by sc_score DESC) AS rank1FROM score) AS sc
WHERE rank1<&#61;3
;

19. 查询每门课程被选修的学生数

SELECT cr.c_name, count(sc.s_id)
FROM score AS sc RIGHT JOIN course AS cr
ON sc.c_id &#61; cr.c_id
GROUP BY cr.c_name;

20. 查询出只选修两门课程的学生学号和姓名

SELECT st.s_id, st.s_name
FROM student AS st
INNER JOIN (SELECT s_id, count(c_id) AS count_c_idFROM scoreGROUP BY s_id) AS sc
ON st.s_id &#61; sc.s_id
WHERE sc.count_c_id &#61; 2
;
/*原博主的方法*/
SELECT s_id, s_name FROM student
WHERE s_id IN (SELECT s_id FROM (SELECT s_id, count(c_id) AS count_c_id FROM score GROUP BY s_id) AS scWHERE count_c_id &#61; 2
);

21. 查询男生、女生人数

SELECT s_sex, count(s_id) FROM student GROUP BY s_sex;

22. 查询名字中含有「风」字的学生信息

/*使用了正则表达式*/
SELECT student.* FROM student WHERE s_name~&#39;.*风.*&#39;;SELECT student.* FROM student WHERE s_name LIKE &#39;%风%&#39;;

23. 查询同名同性学生名单&#xff0c;并统计同名人数

WITH RECURSIVE st1 AS (SELECT s_name, count(s_name) AS count_name FROM student GROUP BY s_name, s_sex
)
SELECT student.s_name FROM student LEFT JOIN st1 ON student.s_name &#61; st1.s_name WHERE st1.count_name>1;

24. 查询 1990 年出生的学生名单

SELECT * FROM student WHERE EXTRACT(YEAR FROM s_age)&#61;1990;

25. 查询每门课程的平均成绩&#xff0c;结果按平均成绩降序排列&#xff0c;平均成绩相同时&#xff0c;按课程编号升序排列

SELECT c_id, avg(sc_score) AS avgsc
FROM score
GROUP BY c_id
ORDER BY avgsc DESC, c_id
;

26. 查询平均成绩大于等于 85 的所有学生的学号、姓名和平均成绩

SELECT st.s_id, st.s_name, sc.avg_score
FROM student AS st INNER JOIN (SELECT s_id, avg(sc_score) AS avg_score FROM score GROUP BY s_id) AS sc
ON st.s_id &#61; sc.s_id
WHERE sc.avg_score>&#61;85;

27. 查询课程名称为「数学」&#xff0c;且分数低于 60 的学生姓名和分数

SELECT s_id, sc_score
FROM score LEFT JOIN course
ON score.c_id &#61; course.c_id
WHERE course.c_name&#61;&#39;数学&#39; AND score.sc_score<60;

28. 查询所有学生的课程及分数情况&#xff08;存在学生没成绩&#xff0c;没选课的情况&#xff09;

SELECT st.s_name, sc2.c_name, sc2.sc_score FROM (SELECT sc.s_id, course.c_name, sc.sc_score FROM score AS sc LEFT JOIN course ON sc.c_id &#61; course.c_id)
AS sc2 RIGHT JOIN student AS st
ON sc2.s_id &#61; st.s_id;

29. 查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数

SELECT st.s_name, sc2.c_name, sc2.sc_score FROM (SELECT sc.s_id, course.c_name, sc.sc_score FROM score AS sc LEFT JOIN course ON sc.c_id &#61; course.c_id)
AS sc2 RIGHT JOIN student AS st
ON sc2.s_id &#61; st.s_id
WHERE sc2.sc_score>&#61;70;

30. 查询不及格的课程

SELECT st.s_name, sc2.c_name, sc2.sc_score FROM (SELECT sc.s_id, course.c_name, sc.sc_score FROM score AS sc LEFT JOIN course ON sc.c_id &#61; course.c_id)
AS sc2 RIGHT JOIN student AS st
ON sc2.s_id &#61; st.s_id
WHERE sc2.sc_score<60;

31. 查询课程编号为 01 且课程成绩在 80 分以上的学生的学号和姓名

SELECT st.s_id, st.s_name
FROM student AS st RIGHT JOIN score AS sc
ON st.s_id&#61;sc.s_id
WHERE sc.c_id &#61; &#39;01&#39; AND sc.sc_score>&#61;80;

32. 求每门课程的学生人数

SELECT c_id, count(s_id) FROM score GROUP BY c_id;

33. 成绩不重复&#xff0c;查询选修「张三」老师所授课程的学生中&#xff0c;成绩最高的学生信息及其成绩

SELECT st.*, sc.sc_score
FROM student AS st RIGHT JOIN score AS sc
ON st.s_id &#61; sc.s_id
WHERE sc.c_id &#61; (SELECT c_id FROM course INNER JOIN teacher ON course.t_id &#61; teacher.t_id WHERE teacher.t_name &#61; &#39;张三&#39;)
ORDER BY sc_score DESC
LIMIT 1;

34. 成绩有重复的情况下&#xff0c;查询选修「张三」老师所授课程的学生中&#xff0c;成绩最高的学生信息及其成绩

成绩有重复&#xff0c;意味着成绩最高的可能是多个

SELECT st.*, sc.sc_score
FROM student AS st RIGHT JOIN score AS sc
ON st.s_id &#61; sc.s_id
WHERE sc.sc_score &#61; (SELECT max(sc2.sc_score) FROM score AS sc2 WHERE c_id &#61; (SELECT c_id FROM course INNER JOIN teacher ON course.t_id &#61; teacher.t_id WHERE teacher.t_name &#61; &#39;张三&#39;))
;

35. 查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩

WITH RECURSIVE sc2 AS (SELECT c_id, count(s_id) as count_s_id, sc_score FROM score GROUP BY c_id, sc_score)
SELECT sc.s_id, sc.c_id, sc.sc_score
FROM score AS sc INNER JOIN sc2
ON sc.sc_score &#61; sc2.sc_score AND sc.c_id &#61; sc2.c_id
WHERE sc2.count_s_id >1;

36. 查询每门功课成绩最好的前两名

SELECT st.s_id, st.s_name, sc.c_id, sc.rank1
FROM student AS st
RIGHT JOIN (SELECT s_id, c_id, ROW_NUMBER() over(PARTITION BY c_id order by sc_score DESC) AS rank1 FROM score) AS sc
ON st.s_id &#61; sc.s_id
WHERE sc.rank1<3
ORDER BY sc.c_id, sc.rank1
;

37. 统计每门课程的学生选修人数&#xff08;超过 5 人的课程才统计&#xff09;

SELECT c_id, count_s_id
FROM (SELECT c_id, count(s_id) AS count_s_id FROM score GROUP BY c_id) AS sc
WHERE count_s_id>5;

38. 检索至少选修两门课程的学生学号

SELECT s_id
FROM (SELECT s_id, count(c_id) AS count_c_id FROM score GROUP BY s_id) AS sc
WHERE count_c_id>1;

39. 查询选修了全部课程的学生信息

SELECT s_id
FROM (SELECT s_id, count(c_id) AS count_c_id FROM score GROUP BY s_id) AS sc
WHERE count_c_id&#61;3;

40. 查询各学生的年龄&#xff0c;只按年份来算

SELECT s_id, EXTRACT(YEAR FROM NOW())-EXTRACT(YEAR FROM s_age) AS age
FROM student;

41. 按照出生日期来算&#xff0c;当前月日 <出生年月的月日则&#xff0c;年龄减一

SELECT s_id, date_part(&#39;year&#39;,age(s_age)) AS age
FROM student;

42. 查询本周过生日的学生

SELECT s_id,s_name,s_age FROM (SELECT s_id,s_name,s_age, EXTRACT(week FROM s_age) AS num_week FROM student) AS st
WHERE num_week &#61; EXTRACT(week FROM now());

43. 查询下周过生日的学生

SELECT s_id,s_name,s_age FROM (SELECT s_id,s_name,s_age, EXTRACT(week FROM (s_age - interval &#39;1 week&#39;)) AS num_week FROM student) AS st
WHERE num_week &#61; EXTRACT(week FROM now());

44. 查询本月过生日的学生

SELECT s_id,s_name,s_age FROM (SELECT s_id,s_name,s_age, date_part(&#39;month&#39;, s_age) AS birth_monthFROM student) AS st
WHERE birth_month &#61; EXTRACT(month FROM now());

45. 查询下月过生日的学生

SELECT s_id,s_name,s_age FROM (SELECT s_id,s_name,s_age, EXTRACT(month FROM (s_age - interval &#39;1 month&#39;)) AS num_month FROM student) AS st
WHERE num_month &#61; EXTRACT(month FROM now());&#96;


推荐阅读
  • SQLite数据库CRUD操作实例分析与应用
    本文通过分析和实例演示了SQLite数据库中的CRUD(创建、读取、更新和删除)操作,详细介绍了如何在Java环境中使用Person实体类进行数据库操作。文章首先阐述了SQLite数据库的基本概念及其在移动应用开发中的重要性,然后通过具体的代码示例,逐步展示了如何实现对Person实体类的增删改查功能。此外,还讨论了常见错误及其解决方法,为开发者提供了实用的参考和指导。 ... [详细]
  • 深入解析 SQL 数据库查询技术
    本文深入探讨了SQL数据库查询技术,重点讲解了单表查询的各种方法。首先,介绍了如何从表中选择特定的列,包括查询指定列、查询所有列以及计算值的查询。此外,还详细解释了如何使用列别名来修改查询结果的列标题,并介绍了更名运算的应用场景和实现方式。通过这些内容,读者可以更好地理解和掌握SQL查询的基本技巧和高级用法。 ... [详细]
  • 本文详细介绍了在 Oracle 数据库中使用 MyBatis 实现增删改查操作的方法。针对查询操作,文章解释了如何通过创建字段映射来处理数据库字段风格与 Java 对象之间的差异,确保查询结果能够正确映射到持久层对象。此外,还探讨了插入、更新和删除操作的具体实现及其最佳实践,帮助开发者高效地管理和操作 Oracle 数据库中的数据。 ... [详细]
  • 在关系型数据库中,数据约束是指在向数据表中插入数据时必须遵循的限制条件。在MySQL和MariaDB中,常见的数据约束包括主键约束、唯一键约束、外键约束以及非空约束等。这些约束确保了数据的完整性和一致性,是数据库管理中的重要组成部分。通过合理设置和使用这些约束,可以有效防止数据冗余和错误,提升数据库的可靠性和性能。 ... [详细]
  • NOIP2000的单词接龙问题与常见的成语接龙游戏有异曲同工之妙。题目要求在给定的一组单词中,从指定的起始字母开始,构建最长的“单词链”。每个单词在链中最多可出现两次。本文将详细解析该题目的解法,并分享学习过程中的心得体会。 ... [详细]
  • MyISAM和InnoDB是MySQL中最为广泛使用的两种存储引擎,每种引擎都有其独特的优势和适用场景。MyISAM引擎以其简单的结构和高效的读取速度著称,适用于以读操作为主、对事务支持要求不高的应用。而InnoDB引擎则以其强大的事务处理能力和行级锁定机制,在需要高并发写操作和数据完整性的场景下表现出色。选择合适的存储引擎应综合考虑业务需求、性能要求和数据一致性等因素。 ... [详细]
  • 提升Android开发效率:Clean Code的最佳实践与应用
    在Android开发中,提高代码质量和开发效率是至关重要的。本文介绍了如何通过Clean Code的最佳实践来优化Android应用的开发流程。以SQLite数据库操作为例,详细探讨了如何编写高效、可维护的SQL查询语句,并将其结果封装为Java对象。通过遵循这些最佳实践,开发者可以显著提升代码的可读性和可维护性,从而加快开发速度并减少错误。 ... [详细]
  • 如何使用mysql_nd:Python连接MySQL数据库的优雅指南
    无论是进行机器学习、Web开发还是爬虫项目,数据库操作都是必不可少的一环。本文将详细介绍如何使用Python通过 `mysql_nd` 库与 MySQL 数据库进行高效连接和数据交互。内容涵盖以下几个方面: ... [详细]
  • 如何在MySQL中选择合适的表空间以优化性能和管理效率
    在MySQL中,合理选择表空间对于提升表的管理和访问性能至关重要。表空间作为MySQL中用于组织和管理数据的一种机制,能够显著影响数据库的运行效率和维护便利性。通过科学地配置和使用表空间,可以优化存储结构,提高查询速度,简化数据管理流程,从而全面提升系统的整体性能。 ... [详细]
  • MySQL索引详解及其优化策略
    本文详细解析了MySQL索引的概念、数据结构及管理方法,并探讨了如何正确使用索引以提升查询性能。文章还深入讲解了联合索引与覆盖索引的应用场景,以及它们在优化数据库性能中的重要作用。此外,通过实例分析,进一步阐述了索引在高读写比系统中的必要性和优势。 ... [详细]
  • 如何高效启动大数据应用之旅?
    在前一篇文章中,我探讨了大数据的定义及其与数据挖掘的区别。本文将重点介绍如何高效启动大数据应用项目,涵盖关键步骤和最佳实践,帮助读者快速踏上大数据之旅。 ... [详细]
  • 针对MySQL Undo空间满载及Oracle Undo表空间溢出的问题,本文详细探讨了其原因与解决策略。首先,通过启动SQL*Plus并以SYS用户身份登录数据库,查询当前数据库的UNDO表空间名称,确认当前状态。接着,分析导致Undo空间满载的常见原因,如长时间运行的事务、频繁的更新操作等,并提出相应的解决方案,包括调整Undo表空间大小、优化事务管理、定期清理历史数据等。最后,结合实际案例,提供具体的实施步骤和注意事项,帮助DBA有效应对这些问题。 ... [详细]
  • 深入解析C#中app.config文件的配置与修改方法
    在C#开发过程中,经常需要对系统的配置文件进行读写操作,如系统初始化参数的修改或运行时参数的更新。本文将详细介绍如何在C#中正确配置和修改app.config文件,包括其结构、常见用法以及最佳实践。此外,还将探讨exe.config文件的生成机制及其在不同环境下的应用,帮助开发者更好地管理和维护应用程序的配置信息。 ... [详细]
  • 在Node.js中调用MySQL存储过程`updateUser(p1, p2, @p3)`时,其中`@p3`为输出参数。若更新操作失败,则返回0;成功则返回1。本文将详细介绍如何正确获取存储过程的返回结果,并确保在实际应用中能够顺利执行。 ... [详细]
  • 在C#中开发MP3播放器时,我正在考虑如何高效存储元数据以便快速检索。选择合适的数据结构,如字典或数组,对于优化性能至关重要。字典能够提供快速的键值对查找,而数组则在连续存储和遍历方面表现优异。根据具体需求,合理选择数据结构将显著提升应用的响应速度和用户体验。 ... [详细]
author-avatar
痞子343
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有