usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication9{classProgram {Static voidMain (string[] args) {
SQL as follows, I translate it into code to deepen understanding//SELECT MAX (id) from Sys_menu E1//WHERE//(SELECT COUNT (DISTINCT (e2.id)) from Sys_menu E2//WHERE e2.id > E1.id//) = 1; --9990List<int> list =Newlist<int> {1,2,3, -, the }; intMax =0; foreach(varId1inchlist) { intCount =0; varDIC =Newdictionary<int,int>(); foreach(varId2inchlist) { if(!DiC. ContainsKey (ID2)) {if(id2>id1) {Count++; } Dic[id2]=1; } } //The above code shows that id2>id1 so id1 can not be the largest, and more than the ID1 requirements can only have one, then said idiom bar under one person, million people above (note this at least 2 elements to make sense)//So it also shows that the above SQL has a trap select MAX (ID) to select ID is also possible, but in fact MAX also returns a null value for no record if(Count! =1) { Continue; } if(max = =0) {Max=id1; } Else if(id1>max) {Max=id1; }} Console.WriteLine (max); Console.read (); } }}
SQL for the second-to-last number, inefficient, but novel