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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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