我正在尝试显示三列中的最高分并按此顺序排序,它确实按每列的最高分数排序,但不返回姓氏和名字。以下是代码的一部分。
import sqlite3
connection = sqlite3.connect("class1.db")
cursor = connection.cursor()
cursor.execute('''SELECT score1, score2, score3,
CASE
WHEN score1 >= score2 AND score1 >= score3 THEN score1
WHEN score2 >= score1 AND score2 >= score3 THEN score2
WHEN score3 >= score1 AND score3 >= score2 THEN score3
ELSE score1
END AS high_score FROM class1 ORDER BY high_score DESC;''' )
print("Class 1:")
result = cursor.fetchall()
for r in result:
print(r)
这是它应该返回的数据:
Class 1:
('Python', 'Monty', 5, 10, 7)
这是它返回的数据:
Class 1:
(5, 10, 7, 10)
我不知道问题是什么,我对SQL
语法不满意,任何帮助都会受到赞赏。包含'Python'和'monty'的列分别称为Surname和Forename。
答案 0 :(得分:1)
您应该将<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function call()
{
var name = document.getElementById("uname").value;
var file = document.getElementById("file").value;
alert(name + file);
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if(xhttp.status == 200 && xhttp.readyState == 4)
{
var response = xhttp.responseText;
document.getElementById("demo").innerHTML = response ;
}
xhttp.open("GET","http://127.0.0.1/Jarvis/json.html?name="+JSON.parse(response)+"&file="+file+"&submit=Submit",true);
xhttp.send();
}
</script>
</head>
<body>
<form action="" method="get" >
<input type="text" name="name" id="uname"/><br/><br/>
<input type="file" name="file"id="fname" size="50"/><br/><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
<p id="demo"></p>
</body>
</html>
和surname
与forename
,score1
和score2
一起添加到所选字段。
score3
详细了解选择查询here。
代码学院提供免费的互动cursor.execute('''SELECT surname, forename, score1, score2, score3
...
课程,请在https://www.codecademy.com/learn/learn-sql查看。