我有一个包含两列的表:第一列包含id(从1到10),第二列包含sales。我按照desc顺序对销售列进行了排序。在这之后,我想以相同的顺序(从1到10)看到Id列。我怎么做?在此先感谢。(我使用的是Microsoft sql server btw) 我忘了提到我想在新表中看到这个。我的意思是在新表中,销售将采用新的ID(从1到10)的desc顺序。很抱歉提到这一点。感谢。
答案 0 :(得分:1)
SELECT Id, Sales, ROW_NUMBER() OVER(ORDER BY sales DESC)
FROM table
ORDER BY sales DESC
答案 1 :(得分:0)
试试这个,
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND
password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$secondQuery = "SELECT * FROM users WHERE userid='$emptyUserid'
AND hash='$emptyHash'";
$result = mysqli_query($db,$secondQuery);
$row = mysqli_fetch_row($result);
$emptyUserid = $row['userid'];
$emptyHash = $row['hash'];
setcookie("userid","$emptyUserid",time()+ (3600 * 24 * 7));
setcookie("hash","$emptyHash",time()+ (3600 * 24 * 7));
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}