有没有办法在结果生成后使用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) 我在使用远程方法的查找中使用简单的排序过滤器时遇到了麻烦:
/**
* 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) 你能帮我搞清楚吗?
q = [[12, 13, 14], [8, 9, 10,11], [2, 3, 4], [5, 6, 7]]
Run Code Online (Sandbox Code Playgroud)
假设我有一个像q这样的列表,我如何根据它进行排序
输出应该是:
q = [[8,9,10,11],[12,13,14][5,6,7],[1,2,3]]
Run Code Online (Sandbox Code Playgroud) 我在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。
必须为在报告中显示的行组数据实现此逻辑。
如果有人可以帮助我,将不胜感激。
谢谢。
我有一个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的第一个值而不是第二个值对列表进行排序.
有没有办法根据折旧系数对所有对象进行排序?
我希望看清单(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)
这有用吗?它在两个字符串的列表中给出了一个非常奇怪的列表输出.
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中出现了分段错误.它是如此有线.谁知道发生了什么?
我有一个具有多个属性的对象数组.给出以下数组:
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) 好的,所以我一直在处理一些带注释的文本输出.到目前为止,我所拥有的是一个字典,其中注释为关键字,关系是一系列元素:
'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) 假设我有以下两个列表..
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) sorting ×10
python ×4
list ×3
arrays ×2
c# ×1
c++ ×1
dictionary ×1
javascript ×1
lambda ×1
linq ×1
loopback ×1
loopbackjs ×1
mysql ×1
node.js ×1
php ×1
ssrs-2008 ×1
ssrs-2008-r2 ×1
ssrs-2012 ×1
string ×1