gpt4 book ai didi

c# - 从 mysql 查询中获取正确的顺序或结果

转载 作者:行者123 更新时间:2023-11-29 07:26:11 26 4
gpt4 key购买 nike

我使用的是 C#。

我试图运行一个查询来获取数据库中的最后 20 个结果,但它现在像这样返回它们,并说最后一个条目是数字“1211”。

1211
1210
1209 .. etc

如果最后一个条目是“1211”,我需要它从“1191”开始并递增!

我现在正在使用这个:

string query = string.Format("
SELECT mesgnumber, targetid, targettype, data, timestamp, sendingid, contenttype
FROM history
WHERE targetid='{0}'
AND targettype='{1}'
ORDER BY mesgnumber DESC
LIMIT 20",
target, IsGroupToInt);

尝试了很多方法,都没有效果。我认为以下内容会起作用,但事实并非如此:

string query = string.Format("
SELECT mesgnumber, targetid, targettype, data, timestamp, sendingid, contenttype
FROM history
WHERE targetid='{0}'
AND targettype='{1}'
ORDER BY mesgnumber DESC
LIMIT 20,
mesgnumber ASC", target, IsGroupToInt);

希望有人能帮忙。

最佳答案

在子查询中按一个方向排序,然后在主查询中反转顺序:

SELECT *
FROM (SELECT ... ORDER BY mesgnumber DESC LIMIT 20) AS subquery
ORDER BY mesgnumber ASC

关于c# - 从 mysql 查询中获取正确的顺序或结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34457803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com