oracle如何查询分数最高同学的信息并且计算记录的条数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle如何查询分数最高同学的信息并且计算记录的条数相关的知识,希望对你有一定的参考价值。

oracle如何查询分数最高同学的信息并且计算记录的条数

参考技术A 使用oracle中count(*)函数来计算总条数。
语句:select count(*) from tablename;
如果是需要所有的表的话,必须先通过:”SELECT table_name FROM user_tables“语句查询出所有的表名,然后在进行条数计算。

Python:从txt读取分数并显示最高分数和记录

从Python第6章练习开始

  1. 高分假设计算机磁盘上存在一个名为scores.txt的文件。它包含一系列记录,每个记录都有两个字段–一个名称,然后是一个分数(1到100之间的整数)。编写一个程序,显示具有最高分数的记录的名称和分数,以及文件中的记录数。 (提示:使用变量和“ if”语句来跟踪您在读取记录时发现的最高分数,并使用变量来记录记录数。)
Data in grades.txt
Jennifer 89
Pearson 90
Nancy 95
Gina 100
Harvey 98
Mike 99
Ross 15
Test 90
file=open('grades.txt','r')
my_list=[]

num_of_records=0
highest_score=1
highest_score_name=''

for line in file:
    name,score=line.strip().split()
    if int(score)>highest_score:
        highest_score=int(score)
        highest_score_name=name

    num_of_records=num_of_records+1


print('the name and score of the record with highest score:')
print('Name:',highest_score_name)
print('Score:',highest_score)

print('
Number of records:',num_of_records)

file.close()

这里是使用python的全部入门,并试图通读本书。但是与此问题打错]

错误:

line 9, in <module> name,score=line.strip().split() ValueError: not enough values to unpack (expected 2, got 0)

感谢任何向导

答案

根据您的评论,您遇到了此错误:

line 9, in <module> name,score=line.strip().split() ValueError: not enough values to unpack (expected 2, got 0)

这表示文件的一行出现问题。我认为您的文件中有一个空行。您可以在解压缩值之前进行检查,或者使用try / except进行错误处理。在您还很早的时候,我认为检查行是否包含任何内容与学习进度相当:

if line.strip():
    name,score=line.split()

这样,如果变量在删除空格后不为空,则只打开行的包装。

另一答案

[知道了,实际上是您的数据在文件末尾有换行符,当您尝试拆分时会导致错误。这是正确的代码:

file = open('Scores.txt', 'r')

num_of_records = 0
highest_score = 1
highest_score_name = ''

for line in file:
    line = line.strip()
    # Check whether the line is empty
    if line == '':
        continue

    name, score = line.split()
    if int(score) > highest_score:
        highest_score = int(score)
        highest_score_name = name

    num_of_records = num_of_records+1


print('the name and score of the record with highest score:')
print('Name:', highest_score_name)
print('Score:', highest_score)

print('
Number of records:', num_of_records)

file.close()

希望它对您有帮助:)

以上是关于oracle如何查询分数最高同学的信息并且计算记录的条数的主要内容,如果未能解决你的问题,请参考以下文章

查询score中选学多门课程的同学中分数为非最高分成绩的记录。

如何结合这两个查询来计算排名变化?

课数据库SQL语句练习题

sql 如何查询每个班级中的最高分

查询每门课成绩最高分的同学的sql语句,输出课程名,姓名,学号,分数。表的结构如下。写出完整的sql语句

Python:从txt读取分数并显示最高分数和记录