标签: sorting

在已生成结果后重新排序sql

有没有办法在结果生成后使用mySQL sql.

我有一个sql获取我想要显示的结果基本上但我想要对它们进行排序的方式取决于结果本身.为清晰起见,提供了一些伪代码.

$sql = "SELECT * FROM post_info WHERE poster = 'login_user' OR replier = 'login_user'";

if ('login_user' == $row['poster']) { //sort by one column } 
else { //sort by a different column }
Run Code Online (Sandbox Code Playgroud)

php mysql sorting

1
推荐指数
1
解决办法
40
查看次数

在模型的远程方法中使用查找时,回送顺序过滤器错误:

我在使用远程方法的查找中使用简单的排序过滤器时遇到了麻烦:

    /**
 * This remote method exposes the meals history from the current logged in user
 */
Meal.listMeals = function(req, res, cb) {
  Meal.find({
    where: {patientId: req.accessToken.userId},
    order: {mealDate: 'DESC'}
  }, cb);
};
Meal.remoteMethod('listMeals', {
  returns: {arg: 'meals', type: 'array'},
  http: {path:'/list-meals', verb: 'get'},
  accepts: [
    {arg: 'req', type: 'object', http: {source: 'req'}},
    {arg: 'res', type: 'object', http: {source: 'res'}}
  ]
});
Run Code Online (Sandbox Code Playgroud)

在上方,您可以看到我的remote / find实现,它在没有订单过滤器的情况下也可以正常运行。

订单{“ mealDate”:“ DESC”}无效

mealDate是我模型上的Date类型。

"properties": {
"mealDate": {
  "type": "date",
  "required": true,
  "default": "Date.now"
}, …
Run Code Online (Sandbox Code Playgroud)

sorting loopback node.js loopbackjs

1
推荐指数
1
解决办法
1461
查看次数

基于最大长度和最大总和进行排序

你能帮我搞清楚吗?

q = [[12, 13, 14], [8, 9, 10,11], [2, 3, 4], [5, 6, 7]]
Run Code Online (Sandbox Code Playgroud)

假设我有一个像q这样的列表,我如何根据它进行排序

  1. 子列表的最大长度和
  2. 子列表的最大总和

输出应该是:

q = [[8,9,10,11],[12,13,14][5,6,7],[1,2,3]]
Run Code Online (Sandbox Code Playgroud)

python sorting list

1
推荐指数
1
解决办法
39
查看次数

SSRS报告自定义排序顺序

我在SSRS表中的行组之一中需要自定义排序时遇到一些问题。

自定义排序顺序的逻辑-

如果行组值包含特定值,则应始终将其显示在底部,而所有其他值必须按升序显示。

例如-

假设从值列表中A,E,G,D,C,and F,“ D”应始终显示在最后,而其他元素将按升序排序。

因此,以上列表应按以下顺序排序- A,B,C,E,F,G,D

或者,如果元素列表为-,P,J,M,N,D,C,K 则所需的排序顺序为- C,J,K,M,N,P and D。

必须为在报告中显示的行组数据实现此逻辑。

如果有人可以帮助我,将不胜感激。

谢谢。

sorting reporting-services ssrs-2008 ssrs-2008-r2 ssrs-2012

1
推荐指数
2
解决办法
9747
查看次数

根据列表属性的第二个值对对象列表进行排序

我有一个Car对象列表,每个对象定义如下:

class Car:
    def __init__(self, vin, name, year, price, weight, desc, owner):
        self.uid = vin
        self.name = name
        self.year = year
        self.price = price
        self.weight = weight
        self.desc = desc
        self.owner = owner
        self.depreciation_values = self.get_depreciation_values(name, vin)
Run Code Online (Sandbox Code Playgroud)

depreciation_values属性是一个包含8个组件的列表,如下所示:

[-12.90706937872767, -2.2011534921064739, '-17', '-51.52%', '-7', '-2.75%', '-5', '-1.74%']
Run Code Online (Sandbox Code Playgroud)

第二个值(-2.2011534921064739)表示折旧因子,我正在尝试将其用作排序键.

我知道attrgetter:

car_list.sort(key=attrgetter('depreciation_values'))
Run Code Online (Sandbox Code Playgroud)

但是这会根据depreciation_values的第一个值而不是第二个值对列表进行排序.

有没有办法根据折旧系数对所有对象进行排序?

python sorting

1
推荐指数
1
解决办法
395
查看次数

在将列表与另一个列表python进行比较时,检查列表中缺少的内容

我希望看清单(B)中列表(A)中缺少的内容

如果我有以下字符串列表:

A = ['4-5', '3-6', '3-3', '9-0']并且B = ['4-4', '4-5', '3-3', '6-9', '5-5', '3-2', '6-6', '9-9', '9,0']想要检查列表B中A的缺失.

A = [ 4-5,3-6,3-3,9-0 ] B = [4-4,4-5,3-3,6-9,5-5,3-6,3-2, 6-6,9-9,9,0 ]

所以...从上面的例子中,我希望它输出['4-4', '6-9', '5-5', '3-2', '6-6', '9-9'].

如果我对两个列表进行排序,那么最好的方法是什么?

谢谢!

我打算做一些像:

unique = []
for n in A:
    if n not in B:
        unique.append(B)
print(unique)
Run Code Online (Sandbox Code Playgroud)

这有用吗?它在两个字符串的列表中给出了一个非常奇怪的列表输出.

python sorting list

1
推荐指数
1
解决办法
51
查看次数

分段错误:C++使用lambda比较器对字符串向量进行排序

int main() {
    vector<string> v(100, "0");
    auto comp = [](const string& first, const string& second)->bool {
        return first.compare(second) <= 0;
    };
    sort(v.begin(), v.end(), comp);
    for(auto s : v) {
        cout<<s<<endl;
    }
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

上面的c ++代码在g ++ v4.9.2中出现了分段错误.它是如此有线.谁知道发生了什么?

c++ sorting string lambda

1
推荐指数
1
解决办法
561
查看次数

JavaScript - 基于特殊订单的属性对对象数组进行排序

我有一个具有多个属性的对象数组.给出以下数组:

var people = [
      {name: "allen", age: 33, color:"green"},
      {name: "jon", age: 23, color:"blonde"},
      {name: "silver", age: 54, color:"yellow"},
      {name: "james", age: 52, color:"grey"},
      {name: "flint", age: 25, color:"pink"},
      {name: "beilly", age: 31, color:"blonde"},
      {name: "bwones", age: 47, color:"grey"},
      {name: "sas", age: 35, color:"green"},
      {name: "jackson", age: 234, color:"yellow"},
      {name: "leonsardo", age: 12, color:"brown"},
      {name: "dicaeprio", age: 73, color:"pink"},
      {name: "sylvfester", age: 35, color:"blonde"},
      {name: "alleen2", age: 33, color:"green"},
      {name: "jofn2", age: 23, color:"blonde"},
      {name: "sdilver2", age: 54, color:"yellow"}, …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting

1
推荐指数
1
解决办法
485
查看次数

按数组python中的字典值排序

好的,所以我一直在处理一些带注释的文本输出.到目前为止,我所拥有的是一个字典,其中注释为关键字,关系是一系列元素:

'Adenotonsillectomy': ['0', '18', '1869', '1716'],
 'OSAS': ['57', '61'],
 'apnea': ['41', '46'],
 'can': ['94', '97', '1796', '1746'],
 'deleterious': ['103', '114'],
 'effects': ['122', '129', '1806', '1752'],
 'for': ['19', '22'],
 'gain': ['82', '86', '1776', '1734'],
 'have': ['98', '102', ['1776 1786 1796 1806 1816'], '1702'],
 'health': ['115', '121'],
 'lead': ['67', '71', ['1869 1879 1889'], '1695'],
 'leading': ['135', '142', ['1842 1852'], '1709'],
 'may': ['63', '66', '1879', '1722'],
 'obesity': ['146', '153'],
 'obstructive': ['23', '34'],
 'sleep': ['35', '40'],
 'syndrome': ['47', '55'],
 'to': ['143', '145', '1852', '1770'], …
Run Code Online (Sandbox Code Playgroud)

python arrays sorting dictionary

1
推荐指数
1
解决办法
34
查看次数

按照在另一个列表C#中找到的值对列表进行排序

假设我有以下两个列表..

var unscoredList = new List<string> { "John", "Robert", "Rebecca" };

var scoredList = new List<WordScore>
{
    new WordScore("John", 10),
    new WordScore("Robert", 40),
    new WordScore("Rebecca", 30)
};
Run Code Online (Sandbox Code Playgroud)

有没有办法我可以unscoredList通过scoredList首先出现得分最高的单词的值对值进行排序unscoredList?

如果需要,下面是WordScore类.

public class WordScore {
    public string Word;
    public int Score;

    public WordScore(string word, int score) {
        Word = word;
        Score = score;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# linq sorting list

1
推荐指数
1
解决办法
86
查看次数