我有这个查询,它会返回用户收藏的音频的ID,按照将该ID标记为收藏的日期排序:
SELECT audio_id FROM favorites
WHERE user_id = ?
ORDER BY `time` DESC
现在,我尝试在屏幕上显示这些音频,也按日期排序
SELECT * FROM audios
WHERE id IN (
SELECT audio_id FROM favorites
WHERE user_id = ?
ORDER BY `time` DESC
)
AND status = '1'
但在查询之后,他们没有按日期排序。第二个查询中ID的顺序与第一个查询中ID的顺序不同。
我该怎么办?我不想存储结果,然后重新订购
答案 0 :(得分:2)
不按时间排序的原因是因为var id =TempData["query"] ;
var ID = Convert.ToInt32(id);
var filesCollection = obj.GetFiles();
var query = (from f in filesCollection
select f.FileId).First();
var convertquery = Convert.ToInt32(query);
string filename = (from f in filesCollection
where f.FileId == ID
select f.FilePath).Single();
string contentType = "application/pdf";
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
return File (fs, contentType);
位于内部ORDER BY
语句中。所以它不适用于外SELECT
这应该适合你:
SELECT
答案 1 :(得分:1)
ORDER BY
子句中查询的WHERE
对SELECT
语句中的数据没有影响。使查询成为连接,允许将数据存储在其当前位置,并且仍然可以进行相应的排序。
SELECT A.*,
f.[time]
FROM audios A INNER JOIN favorites f
ON A.audio_id = f.audio_id
WHERE a.status = '1' and
f.user_id = ?
ORDER BY [time] DESC
答案 2 :(得分:0)
您应该将std::vector<uchar> buff;
cv::imencode(".jpg", frame, buff);
std::ofstream myfile;
myfile.open("example.jpg", std::ios::binary);
for (auto i = buff.begin(); i != buff.end(); ++i)
{
//std::cout << *i;
myfile << *i;
}
myfile.close();
子句放在子查询之外,就像:
ORDER BY
在这个小提琴上试试这个:http://sqlfiddle.com/#!9/ca05bf