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

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 ...

python,max,min,assignment-operator

Per the language reference, "augmented assignment": is the combination, in a single statement, of a binary operation and an assignment statement (emphasis mine). max isn't a binary operation (it takes an arbitrary number of positional arguments plus the key keyword argument), so your proposed operator would not be consistent with...

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,...

You can use MIN in the column list if you group the query appropriately: select a.skucode, a.sizecode, b.colourdescription as colourdesc, a.season, MIN(case when sp.eventnbr in (select eventnbr from event where sysdate between eventbegints and eventendts) then rate else sellprice end) as listprice from sku a INNER JOIN colour b ON...

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...

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...

sql,sql-server,max,average,min

Remove b,c from group by and add period instead SELECT name,period, max(b), max(c), min(b), min(c) FROM tablename group by name,period ...

public static double min(double a, double b): "Returns the smaller of two double values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the...

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) ...

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...

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) ...

There is no method for this in python. You can try using primitive methods to build what you want using lists. This code does the job: #!/usr/bin/python a = [] b = [] nums = raw_input("Enter input- ") #append all to a list for n in nums.split(): n = int(n)...

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...

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....

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]...

// 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...

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; }...

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...

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.

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.

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....

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...

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,...

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...

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...

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...

#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;...

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

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...

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'...

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

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:...

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...

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...

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...

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...

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 <...

There are several ways to do that. 1) A simple one is to use this script. 2) If the data is not large, you can write your own algorithm analyzing gradient in each point or analyzing increment: 1D array jmin=0; jmax=0; for j=2:length(M)-1 if (M(j)>M(j-1))&&(M(j)>M(j+1)) jmax=jmax+1; max_index(jmax)=j; max_value(jmax)=M(j); end; if...

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...

Any efficient way to calculate the maximum element in a 2-D array(or vector in your case) involves a complexity of O(n^2) irrespective of what you do, as the calculation involves a comparison between n*n elements.Best way in terms of ease of use is to use std::max_element on the vector of...

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"...

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:...

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...

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...

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

If df is your original data.frame for "big" data it is recommended to use data.table package: library(data.table) dt = data.table(df) setkey(dt, user) dt[,list(min(value), max(value)),by=user] user V1 V2 1: USER1 1 55 2: USER5 4 8 3: USER3 6 9 4: USER2 2 15 Edit: good example to use each from...

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']) ) {...

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...

# 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...

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: "+...

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...

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...

android,max,min,android-datepicker

You can try replacing this line: return new DatePickerDialog(this, pDateSetListener, pYear, pMonth, pDay); By those: DatePickerDialog dpDialog = new DatePickerDialog(this, pDateSetListener, pYear, pMonth, pDay); DatePicker datePicker = dpDialog.getDatePicker(); Calendar calendar = Calendar.getInstance();//get the current day datePicker.setMaxDate(calendar.getTimeInMillis());//set the current day as the max date return dpDialog; in the same way you...

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...

You need to add two more lines of CSS: To make the % height works use this: html,form {height:100%} And to avoid the padding increase the height of container use this .container-front { box-sizing:border-box; } Check the Snippet Below <!DOCTYPE html> <html> <head> <title>Sticky Header and Footer</title> <style type="text/css"> @font-face...

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;...

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; ...

You can use direct min or max SELECT max(time) from t; SELECT min(time) from t; http://sqlfiddle.com/#!3/3aad3f...

It most likely won't make a lot of difference in terms of performance. Think about what you'd have to do if you decided to do things on one rank instead of via MPI collectives. First, you'd have to do an MPI_GATHER to get all of the data on a single...

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...

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: ...

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 ,...

matlab,min,matrix-multiplication

I don't know your values so i wasn't able to check my code. I am using loops because it is the most obvious solution. Pretty sure that someone from the bsxfun-brigarde ( ;-D ) will find a shorter/more effective solution. alpha = 0:0.05:2; beta = 0:0.05:2; L1(kx3) = [t1(kx1) t2(kx1)...

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...

In Python 2, numeric values always sort before strings and almost all other types: >>> sorted(['a', 5]) [5, 'a'] Numbers then, are considered smaller than strings. When using max(), that means the string is picked over a number. That numbers are smaller is an arbitrary implementation choice. See the Comparisons...

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 Tim's answer you'll have the first item that matches the condition. Just in case you have several items with the same price and you want to have the index of all these items, you can use this : int minPrice = closingsBook.Min(book => book.LimitPrice); var indexes = closingsBook.Select((book, index)...