Most probably you have a variable named min that shadowed the built in min function. If you are using the interactive console just do: del min Also consider using numpy, as it can be faster on bigger lists: >>> import numpy >>> numpy.min(mylist) ...

Maybe I don't understand something, but you can add two columns in group by, like the following example. Just add ,(comma) between the two or more columns. SELECT * FROM performs NATURAL JOIN athletes JOIN (SELECT athlete_id, MIN(perform) AS perform, category_id, discipline_id FROM zaznamy WHERE discipline_id = 4 GROUP BY...

When you write open(file), Python is trying to find the the file tc.out in the directory where you started the interpreter from. You should use the full path to that file in open: with open(os.path.join(root, file)) as f: Let me illustrate with an example: I have a file named 'somefile.txt'...

From the help page on ?min: pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. On the other hand: max and min return the maximum or minimum of all the values present in...

std::max_element http://www.cplusplus.com/reference/algorithm/max_element/ std::min_element http://www.cplusplus.com/reference/algorithm/min_element/

You can use this, This will order from Minimum price vendor product SELECT VENDOR.V_NAME, MIN(PRODUCT.P_PRICE) AS LOWEST_PRICE FROM VENDOR INNER JOIN PRODUCT ON VENDOR.V_CODE = PRODUCT.V_CODE GROUP BY VENDOR.V_NAME ORDER BY LOWEST_PRICE SQL FIDDLE:- http://sqlfiddle.com/#!3/467c8/2...

python-3.x,matrix,max,return-value,min

Use the built-in functions max() and min() after stripping the list of lists: matrix = [[1, 2, 4], [8, 9, 0]] dup = [] for k in matrix: for i in k: dup.append(i) print (max(dup), min(dup)) This runs as: >>> matrix = [[1, 2, 4], [8, 9, 0]] >>> dup...

// Time zero: Buy and sell at the same time, no profit int best_buy_index = 0; int best_sell_index = 0; int min_index = 0; int best_profit = 0; for (int i = 1; i < prices.size(); ++i) { // Profit we'd get if we had bought at the lowest price...

As long as your compiler is optimizing that's probably as good as you're going to get. #include <algorithm> int test(int i, int j, int k) { return std::min(i, std::min(j, k)); } compiled with g++ -S -c -O3 test.cpp I get cmpl %edi, %esi movl %edx, %eax cmovg %edi, %esi cmpl...

oracle,oracle11g,where-clause,min

As well as missing a comma, your subqueries need to be enclosed properly in parentheses; and the ones you already have are unbalanced. Or rather, in the wrong place; you currently start those with SELECT(MIN... where it should be (SELECT MIN.... Move the opening parenthesis to before the subquery's SELECT,...

You don't need to worry about where the data ends, just skip the first two rows: Sub NotTheFirstTwoRows() Dim c As Range Set c = Range("C3:C" & Rows.Count) MsgBox Application.WorksheetFunction.Min(c) End Sub Because any blanks at the bottom of the column will be ignored....

My guess, without seeing your original tables, has to do with the contents of the Name column as opposed to the CEC column. I suspect that if you add the Name column to your result set, the contents of that column for the last two lines will be different for...

I think what you want is to use a Common Table Expression (CTE), which specifies a temporary result set that you can query on. The MIN function used with an OVER clause to divide the result set produced by the FROM clause into partitions to which the function is applied....

sql,sql-server,date,select,min

Use window function SELECT id_user, NAME, last_access, company FROM (SELECT id_user, NAME, last_access, company, Row_number()OVER(partition BY company ORDER BY last_access) rn FROM users u JOIN company c ON u.id_company = c.id_company) a WHERE rn = 1 or join both the tables find the min last_access date per company then join...

If I understand correct and since you're already using dplyr, you could do it like this: library(dplyr); library(tidyr) unite(df, X, ID1:ID2, sep = ".") %>% mutate(Position = row_number()) %>% group_by(X) %>% slice(which.min(value)) #Source: local data frame [4 x 3] #Groups: X # # X value Position #1 1.1 1 1...

You are pretty close. When working with correlated subqueries, always use table aliases to be absolutely clear about where the columns are coming from: select S.Date, Unit_price, (SELECT min(s2.Unit_Price) FROM table s2 WHERE s2.DATE BETWEEN s.DATE - interval 3 day and s.DATE - interval 1 day ) as min_price_3_days FROM...

A generic hash table is not a sorted list of elements. So it's going to be an O(n) operation to find the min() and max() of a given table.

#include <stdlib.h> #include <stdio.h> #include <errno.h> /* Defines: ENOMEM */ int main() { Added rCode to assist in error handling. int rCode=0; Removed xronos as it is not used. int n,i,min; Initialized sum to 0; int sum=0; Initialize array pointer to NULL so cleanup is easier. int *array = NULL;...

The standard SQL to do this is: SELECT bus_id, stop_id, MIN(time) as time FROM tablename GROUP BY bus_id, stop_id ORDER BY bus_id, stop_id This will return the minimum value from the time field for each combination of bus and stop ID. I've also sorted the results using an ORDER BY...

I need to select all graphics software (category) that runs on linux (platform) and I need the minimum, maximum, and average price (version/@price). If, as I suspect, you are using XSLT 1.0, with no support for EXSLT extension functions, try something along the lines of: XSLT 1.0 <xsl:stylesheet version="1.0"...

Given your criteria, the first two points of your sorting algorithm degenerate into one much simpler algorithm. That is: No matter which column is full of 0's, you are always sorting by first column, then by second column, then by third column ascending values. This will leave your target item...

You can get the minimum value first, then get the item that has the minimum value: var minValue = items.Min(x => x.Value); var item = items.First(x => x.Value == minValue); You can also do that in one line that won't be efficient because it will perform Min for each item:...

You could use: DateTime dateFrom = models .SelectMany(d => d.Trans) .Select(tr => Convert.ToDateTime(tr.PostingDate)) .Min(); DateTime dateTo = models .SelectMany(d => d.Trans) .Select(tr => Convert.ToDateTime(tr.PostingDate)) .Max(); If the type of PostingDate is already a DateTime, you don't need the Convert call: DateTime dateFrom = models .SelectMany(d => d.Trans) .Min(tr => tr.PostingDate);...

Replace left--; with the following: left -= (left > 0 ? 1 : 0); ...

For Excel 2010 or later: =IFERROR(LOOKUP(2,1/(C1=AGGREGATE({14,15},6,$C$1:$C$12,1)),{"MAX","MIN"}),"") Regards...

prolog,order,min,swi-prolog,sicstus-prolog

The actual source of confusion is a common problem with general Prolog code. There is no clean, generally accepted classification of the kind of purity or impurity of a Prolog predicate. In a manual, and similarly in the standard, pure and impure built-ins are happily mixed together. For this reason,...

javascript,arrays,object,max,min

You could call Math.min and Math.max, passing in a mapped array containing only the relevant values like this: function endProp( mathFunc, array, property ) { return Math[ mathFunc ].apply(array, array.map(function ( item ) { return item[ property ]; })); } var maxY = endProp( "max", pts, "Y" ), // 8.389...

This is equivalent to SELECT i601_ID, MIN(row) AS row FROM SortPlaetzeDate. It assigns the name "row" to the second column. "AS" is optional.

The main problem here is the last line: else (temp)))))) The parentheses are incorrect here—the else keyword needs to be within the parens. Changing that to this: (else temp)))))) ...fixes the algorithm. You also aren't calling maxmin properly—it needs a list, not a series of parameters. Your final line of...

If you take the difference (using diff) then you're looking for where the difference is greater than 0. We search for the first time that happens u <- c(.5, .4, .3, .6) min(which(diff(u) > 0)) This gives us 3 which is close to what we want but not exactly. Since...

With data like: Use the array formula: =MIN(IF((B1:B10="Credit")*(A1:A10>0),A1:A10)) Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key....

There's no need for the outer loop, it only runs once and you don't use i anyway. why do you have it? For the inner loop, you need to compare against the minimum value. Right now you are comparing it against the first element in the array, which is not...

you can get min , max dates in a subquery and then can get the results. select member_id, upper(name), registration_date from db.member cross join ( select min(registration_date) as minDate, max(registration_date) as maxDate from db.member ) t where registration_date in ( t.minDate, t.maxDate) or you can do it with in and...

If I understand correctly, this query is a bit trickier than it seems. Use a subquery to get the counts per category, using a window function to get the minimum count. Then join this back to the original data: select s.model, s.VIN, s.cost from stock s join (select category, count(*)...

java,multidimensional-array,min

I would say, there are two things that you need to know here. As all are saying the index starts from 0. So in both your loops, it should start from 0 only. So, for (int row = 0; row < array1.length; row++){ for (int col = 0; col <...

Something like >>> a_set = set(['A', 'BF', 'B', 'BA', 'ABF', 'AF', 'F', 'BFA', 'AFB', 'BAF', 'FA', 'FB', 'AB', 'FAB', 'FBA']) >>> min_len = min( len(x) for x in a_set ) >>> [ x for x in a_set if len(x) == min_len ] ['A', 'B', 'F'] To split it up min_len...

c#,linq,extension-methods,ienumerable,min

This could happen if enumerable changes between the calls. It seems GetNetworkRoutes uses lazy evalution to return the result. And that's why it's result is enumerated each time you call Min method on it. So the second returns different results and that's why the min. value you get is different....

Depending on your RDBMS, you may be able to use ROW_NUMBER() to assign a ranking to each record and pick the one's that rank first. This is faster than using additional joins or correlated sub-queries, but isn't, for example, supported in MySQL at present. WITH sorted_supplies AS ( SELECT supplies.*,...

I think all of your sub-queries can be replaced with this simple one ;WITH CTE AS ( SELECT * , ROW_NUMBER() OVER (PARTITION BY c_code ORDER BY c_key) rn FROM c_dim WHERE flag = 'X' ) DELETE FROM CTE WHERE rn > 1 ...

Use LEAST instead of MIN: UPDATE Inventory SET TargetPrice = LEAST(Price1,Price2) WHERE Quantity = 0 MIN is an aggregate function operating on a rowset, whereas LEAST operates on the list of arguments passed. EDIT: UPDATE Inventory SET TargetPrice = LEAST(COALESCE(Price1, Price2), COALESCE(Price2, Price1)) WHERE Quantity = 0 You can use...

One approach would be to store the previous two values lines in two variables, and use a third variable to store the line. So you could get the local minimum like this: awk 'prev!=""&&prev<=prev2&&prev<=$2{print line}{prev2=prev;prev=$2;line=$0}' file and the local maximum like this: awk 'prev!=""&&prev>=prev2&&prev>=$2{print line}{prev2=prev;prev=$2;line=$0}' file ...

java,arrays,loops,return-value,min

The logic of your program is: 1. Declaring an array of names. 2. Declaring an array of times. 3. Writing the names and times through a loop to the console. You also wrote a method to retrieve the minimum value within an int array, but you did not include that...

# Create some fake data set.seed(14) df = data.frame(power = sample(seq(15,31,0.5),30, replace=TRUE), total= sample(c(0,1,2,3,7:11), 30, replace=TRUE), found=sample(c(0:2,7:9), 30, replace=TRUE)) df$total[c(5,9)] = NA # Add some missing data # Minimum of `power` at maximum of `total` min(df$power[df$total==max(df$total, na.rm=TRUE)], na.rm=TRUE) [1] 17.5 If you want to see all the values of power...

Here you are using assignment operator = instead of comnparison operator == if (c = 1) The loop for finding minimum and maximum can be written simpler for ( c = 1; c <= n; c++ ) { scanf_s( "%d", &value ); if ( c == 1 ) { max...

python,max,average,min,genetic-algorithm

You have this error because you're calling the method without passing any list (a population in this case).

Something like this will get what you want: SELECT LEFT(FirstIssued, 6) AS YYMM, COUNT(DISTINCT Policy_No) AS NumPolicies FROM ( SELECT Policy_No, MIN(issue_date) AS FirstIssued FROM table_a WHERE indicator = 'fln' GROUP BY Policy_No ) A GROUP BY LEFT(FirstIssued,6) The key is to first find the min date for each policy,...

This: function GetMinMaxPrices(Array $prices) { if (empty($prices)) { return array(); } else { $return_arr = array(); } // Get highest and lowest for all keys: _regular_price, _sale_price, and _price. foreach($prices as $varBar => $price_info) { if ( !('' === $price_info['_price'] && '' === $price_info['_regular_price'] && '' === $price_info['_sale_price']) ) {...

The answer from this link shared in the comments: const double mid = std::max(std::min(x,y),std::min(std::max(x,y),z)); Edit - As pointed out by Alan, I missed out on a case. I have given now a more intuitive proof. Direct Proof: Without Loss of Generality with respect to x and y. Starting with the...

sql,sql-server,database,where-clause,min

Try this, though note technically the value 100 doesn't fall in the range 90-99 and therefore should probably be classed as 11, hence why the value 60 comes out with a scale of 6 rather than your 7: SQL Fiddle MS SQL Server 2008 Schema Setup: Query 1: create table...

group <- "somegroup" groupwiseList$group is not the same as groupwiseList$somegroup You probably want to use groupWiselist[,group] instead. I didn't take the time to fully debug to see if this was the issue but it certainly stuck out to me....

Does this work for you? min(q, key = lambda x: (x[1],x[0])) ...

You can use a generator expression with min. This will set m as the minimum value in a that is greater than 0. It then uses list.index to find the index of the first time this value appears. a = [4, 8, 0, 1, 5] m = min(i for i...

A bit of a non-scalable solution would be to drop 2014 and then call max and min - tr2['max07_13']=tr2.drop('2014', axis=1).max(axis=1) If you know the columns of interest, you can also use that - columns_of_interest = ['2007', '2008', '2009', '2010', '2011', '2012', '2013'] tr2['max07_13']=tr2[columns_of_interest].max(axis=1) ...

select count(VIN), Category from STOCK having count(VIN)=(select max(count(VIN)) from STOCK group by Category ) OR count(VIN)=(select min(count(VIN)) from STOCK group by Category ) group by Category; ...

Update Specific answer : SQL> WITH Equip_price AS 2 ( SELECT 1 pid, 1 equipmentID, 50 price FROM dual 3 UNION ALL 4 SELECT 2 , 2 , 20 FROM dual 5 UNION ALL 6 SELECT 3 , 1 , 100 FROM dual 7 UNION ALL 8 SELECT 4 ,...

You can get the min and max rows separately with df1[which.max(df1[,2]),] Or df1[which.min(df1[,2]),] For plotting, may be df2 <- subset(df1, Number %in% c(min(Number), max(Number))) m1 <- t(df2[,2]) colnames(m1) <- df2[,1] barplot(m1) Update Using the example in the image, dfN <- data.frame(Col1=c('Controlli di Polizia Giudiziaria', 'Ricrosi a seguito di contravvenzioni', 'Ordinanze...

You may use bsxfun like this for a generalized case. Code %%// Slightly bigger example than the original one mat= [ 1 2 3 6; 2 3 4 2; 3 4 5 3;] test = [ 2 3 4 8 5 6 7 1; 3 4 5 3 6 7...

Collect the triagers with tMax value in loop and put them into the string. Set rngValues = [C5:C32] Set rngTables = [A5:A32] tMax = Application.WorksheetFunction.Max(rngValues) idx = Application.Match(tMax, rngValues, 0) For Each IssuesCount In rngValues If IssuesCount.Value = tMax Then Triagers = Triagers & IIf(Triagers = "", "", " and...

Disclaimer: I'll add my own answer to the question just in case anyone else is still interested in more details on the matter. Some theory ... I looks like this issue is more complex than I expected. As Alexey Romanov has already pointed out, the notion of incomparability would require...

how about the following: // assume students.length > 0 static void printMinMax(Student[] students) { Student min = students[0]; Student max = students[0]; for (Student student: students) { if (student.getGrade() > max.getGrade()) max = student; if (student.getGrade() < min.getGrade()) min = student; } System.out.println("Best student: " + max); System.out.println("Worst student: "+...

java,algorithm,collections,min

Keep a hash table of counts for each value, then update it and also the min if there are no more values equal to min in your hash table. // when increasing the i'th count coll[i] += 1; --hashTable[coll[i] - 1]; ++hashTable[coll[i]]; // check whether also to update the max:...

This query based on analytic functions lag() and lead() gives expected output: select id, nid, point from ( select id, point, p1, lead(id) over (order by id) nid from ( select id, point, decode(lag(point) over (order by id), point, 0, 1) p1, decode(lead(point) over (order by id), point, 0, 2)...

UPDATE 2: According to the updated XML sample, assuming that you want to find minimum value of l attribute of line element, try this way : //page/block/text/par/line[not(preceding::line/@l <= @l) and not(following::line/@l<@l)]/@l output : Attribute='l="253"' UPDATE : Actually, by having combination of preceding-sibling::block/@l <= @l and following-sibling::block/@l < @l, there is...

Thanks to @user20650 for the answer: set.seed(1) mx <- matrix(runif(1e7), ncol=5) With apply: system.time(which.min.mx <- apply(mx, 1, which.min)) # user system elapsed # 4.7 0.0 4.7 with max.col: system.time(mx.mins.2 <- max.col(-mx, ties="first")) # user system elapsed # 0.12 0.00 0.13 all.equal(which.min.mx, mx.mins.2) # [1] TRUE Old answer: This is the...

Modify the return signature of your method(s), assign the value to smallest (or biggest) and then return the variable. Like, public static int biggest(int nr1, int nr2, int nr3){ int biggest = 0; if (nr1>nr2 && nr1>nr3){ biggest = nr1; } else if (nr2>nr1 && nr2>nr3){ biggest = nr2; }...

A PivotTable may be easiest, with Name for ROWS and Min of Score and Max of Score for Sigma VALUES. HOWEVER, this gives a min of 170 for Ben: ...

Consider using the package data.table for operations such as this. Here is an example: library(data.table) datadt <- data.table(data) datadt[,Min:=min(Last),by=Date] datadt Which results in your desired result: Date Last Min 1: 2015-06-21 2106.25 2105.25 2: 2015-06-21 2105.25 2105.25 3: 2015-06-21 2105.75 2105.25 4: 2015-06-22 2106.75 2106.75 5: 2015-06-22 2107.00 2106.75 6:...

matlab,min,matrix-multiplication,bsxfun

I believe you need this correction in your code - [minindex_alongL2, minindex_alongL1] = ind2sub([size(L2,1) size(L1,1)],p) For the solution, you need to add the size of p into the index finding in the last step as the vector whose min is calculated has the "added influence" of alpha - [minindex_alongL2, minindex_alongL1,minindex_alongalpha]...

From your Explanation it looks like you need something like below: 1) SELECT Sales , date FROM TABLE_NAME WHERE Sales = ( SELECT MIN(Sales) FROM TABLE_NAME) 2) SELECT Sales , date FROM TABLE_NAME WHERE Sales = ( SELECT MAX(Sales) FROM TABLE_NAME) In single Query SELECT Sales , date FROM TABLE_NAME...

mysql,max,greatest-n-per-group,min,create-table

SELECT tmin.Name, tmin.ValueA, tmax.ValueA, tmin.ValueB1, tmin.ValueB2, tmax.ValueB1, tmax.ValueB2 FROM ( SELECT Name, MAX(ValueA) AS ValueAMax, MIN(ValueA) AS ValueAMin FROM `foo` GROUP BY Name ) AS t JOIN `foo` AS tmin ON t.Name = tmin.Name AND t.ValueAMin = tmin.ValueA JOIN `foo` AS tmax ON t.Name = tmax.Name AND t.ValueAMax = tmax.ValueA;...

You minimum cut is not s, a, c, but s, a, b, c. Its capacity is 5 which is the maximum flow that you've calculated. You can find the minimum cut by using the definition of the residual network. Recall that the Ford-Fulkerson terminates when there are no paths between...

replace <input type="submit"/> to <button type="submit" value="" onclick="minmax();">Submit</button> and add JS function: function minmax() { min(); max(); } ...