max

Maximum in group by active record query

二次信任 提交于 2019-12-23 15:44:00
问题 I have a Model which has two attributes (I am showing only two as only those two columns are needed) MyModel place_id ------------------------ user_id 1 ---------------------------------- 1 1 ---------------------------------- 2 1 ---------------------------------- 2 3 ---------------------------------- 3 3 ---------------------------------- 2 3 ---------------------------------- 3 3 ---------------------------------- 1 I want to fetch group by maximum records. Basically I want to fetch for a

MySQL - Referencing aggregate column in where clause

自古美人都是妖i 提交于 2019-12-23 10:54:25
问题 This seems so simple but I can't seem to figure it out without doing subqueries (which seem to slow down the queries significantly - takes almost 10 seconds instead of <1). Let's say I have a table of sent documents, and I want to select the ones that have been updated since they've last been sent, and the ones that have never been sent. SELECT d.document_id, max(sd.document_sent_date) as last_sent_date FROM documents d LEFT JOIN sent_documents sd ON d.document_id=sd.document_id WHERE last

MySQL - Referencing aggregate column in where clause

大兔子大兔子 提交于 2019-12-23 10:54:14
问题 This seems so simple but I can't seem to figure it out without doing subqueries (which seem to slow down the queries significantly - takes almost 10 seconds instead of <1). Let's say I have a table of sent documents, and I want to select the ones that have been updated since they've last been sent, and the ones that have never been sent. SELECT d.document_id, max(sd.document_sent_date) as last_sent_date FROM documents d LEFT JOIN sent_documents sd ON d.document_id=sd.document_id WHERE last

JPA - MAX of COUNT or SELECT FROM SELECT

余生颓废 提交于 2019-12-23 09:27:18
问题 I wrote the following query for MySQL: SELECT subquery.t1_column1, subquery.t2_id, MAX(subquery.val) FROM ( SELECT t1.column1 as t1_column1, t1.id_t2 AS t2_id, count(1) AS val FROM table1 t1 INNER JOIN table2 t2 ON t2.id = t1.id_t2 GROUP BY t1.id_t2 ) subquery GROUP BY t1_column1 And I'd like to translate it into JPA (JPQL or criteria query). I don't know how to make this max(count) thing, and JPA doesn't seem to like the SELECT FROM SELECT... If anyone has an idea other than native queries

What's the largest value an NSNumber can store?

社会主义新天地 提交于 2019-12-23 07:56:12
问题 What's the largest value an NSNumber can store? // ok NSNumber *value = @(1 << 31); // gives compiler error, so max NSNumber is 32-bit uint? NSNumber *value = @(1 << 32); 回答1: NSNumber is actually a class cluster, meaning that when you create an instance you may be getting any of a variety of concrete subclasses, each capable of storing a different kind of numeric type. The actual types available, and their sizes, may be machine-dependent. Looking at the NSNumber documentation shows you the

find max value of a list with numpy nan [duplicate]

Deadly 提交于 2019-12-23 07:12:24
问题 This question already has an answer here : Numpy: Maximal Value is NaN (1 answer) Closed 2 years ago . import numpy as np print max([np.nan, 1, 2, 3, 4]) print max([1, 2, 3, 4, np.nan]) print max([1, 2, 3, np.nan, 4]) the first will print nan as list's max value the second will print 4 as list's max value the third will print 4 as list's max value Is there a solution for this problem? Make all math function just ignore nan? 回答1: Use np.nanmax() to ignore any NaNs: In [57]: np.nanmax([np.nan,

find max value of a list with numpy nan [duplicate]

那年仲夏 提交于 2019-12-23 07:10:24
问题 This question already has an answer here : Numpy: Maximal Value is NaN (1 answer) Closed 2 years ago . import numpy as np print max([np.nan, 1, 2, 3, 4]) print max([1, 2, 3, 4, np.nan]) print max([1, 2, 3, np.nan, 4]) the first will print nan as list's max value the second will print 4 as list's max value the third will print 4 as list's max value Is there a solution for this problem? Make all math function just ignore nan? 回答1: Use np.nanmax() to ignore any NaNs: In [57]: np.nanmax([np.nan,

Python miminum length/max value in dictionary of lists

末鹿安然 提交于 2019-12-23 06:26:11
问题 Had to re-write the question due to changed requirements. I have a dictionary such as the following: d = {'a': [4, 2], 'b': [3, 4], 'c': [4, 3], 'd': [4, 3], 'e': [4], 'f': [4], 'g': [4]} I want to get the keys that are associated with the smallest length in the dictionary d, as well as those that have the maximum value. In this case, the keys with the smallest length (smallest length of lists in this dictionary) should return 'e, 'f', 'g' And those with the greatest value(the sum of the

Finding Maximum and Minimum values in c++ by user input

有些话、适合烂在心里 提交于 2019-12-23 05:01:06
问题 i want to know how can i find the maximum and minimum value in c++ by user input value and and user also put the limit for for loop , for example : Write a c++ program that initially takes an integer value from the user as the loop’s limit. It means that the loop will execute the same times as the input from the user. The loop will then take integer values as input from the user until it reaches loop limit. You are required to use only one variable which will be used to take input repeatedly

T-SQL: SELECT related column data for the max two other columns

♀尐吖头ヾ 提交于 2019-12-23 03:58:19
问题 I have table data like the following, where order type is 1 for a quote, and 2 for an order. Any given po_num can have 0 to many of order_type 1, but should only have only 0 or 1 of order_type 2, or all of the above. I need to return the max order_num of the max order_type of a given po_num, where the order_num is just an additional (but important) column in my result. Table data: order_type po_num order_num 1 E0102 1013200 1 E0102 1013162 1 E0104 1012161 2 E0104 1012150 1 E0104 1011449 2