druidos Posted October 11, 2005 Report Share Posted October 11, 2005 Sen neesmu neko SELECTojis, tāpēc smadzenes mazliet atrofējušās. :) Vajadzīga palīdzība: Ir tabula: id | username | try | password 1 | user1 | 1 | xxxx 2 | user2 | 1 | xxxx 3 | user3 | 1 | xxxx 4 | user1 | 2 | xxxx 5 | user1 | 3 | xxxx Vajag MySQL selectu (ļoti vēlams bez subselectiem), kura rezultātā izdotu sarakstu: id | username | try | password 5 | user1 | 3 2 | user2 | 1 3 | user3 | 1 T.i. saraksts, kur ir visi username, bet no vienādiem username parādās "id, password", kuram ir augstāks "try". Tnx jau iepriekš. Link to comment Share on other sites More sharing options...
Delfins Posted October 11, 2005 Report Share Posted October 11, 2005 (edited) muļķīgi taisīt kolonnu `try`, jo by default, pēc tava uzdevuma - `try` = rindu skaits select userId, count(*) AS tryCount from UserLog group by userId Edited October 11, 2005 by Delfins Link to comment Share on other sites More sharing options...
druidos Posted October 11, 2005 Author Report Share Posted October 11, 2005 muļķīgi taisīt kolonnu `try`, jo by default, pēc tava uzdevuma - `try` = rindu skaits select userId, count(*) AS tryCount from UserLog group by userId Lieta tāda, ka parole mainās + ir vēl pāris lauki kas mainās. Tavā piedāvājumā izdos pirmo pagadijušos username&password, kurš nebūs derīgs, bet nepieciešami ir pēdejie ievadītie. Piedāvājums saglabāt tikai tagadējos username&password - neder, jo vajadzīga vēsture. Link to comment Share on other sites More sharing options...
Analgiins Posted October 11, 2005 Report Share Posted October 11, 2005 nu tad vajag veel vienu lauku: try_date un tad ORDER BY try_date DESC LIMIT 1 Link to comment Share on other sites More sharing options...
druidos Posted October 11, 2005 Author Report Share Posted October 11, 2005 nu tad vajag veel vienu lauku: try_dateun tad ORDER BY try_date DESC LIMIT 1 Jau mēģināju. Tik un tā izdod pirmoS ierakstuS, vajag pēdejoS. :( Link to comment Share on other sites More sharing options...
Analgiins Posted October 11, 2005 Report Share Posted October 11, 2005 tad tev noteikti vaicaajums nav pareizs, bet kaads vinjsh tev ir, es ar nevaru uzmineet.. Link to comment Share on other sites More sharing options...
druidos Posted October 11, 2005 Author Report Share Posted October 11, 2005 (edited) tad tev noteikti vaicaajums nav pareizs, bet kaads vinjsh tev ir, es ar nevaru uzmineet.. Lūdzu! id | username | try | password | regdatetime 1 | user1 | 1 | xxxx | regdatumi 2 | user2 | 1 | xxxx | 3 | user3 | 1 | xxxx | 4 | user1 | 2 | xxxx | 5 | user1 | 3 | xxxx | SELECT username, count(*) as trys, id, password, regdatetime FROM table GROUP BY username ORDER BY regdatetime DESC Edited October 11, 2005 by druidos Link to comment Share on other sites More sharing options...
Delfins Posted October 11, 2005 Report Share Posted October 11, 2005 Visai loģiski, šie id, password, regdatetime būs randomā... jo groupings to neatbalsta - pēdējās vērtības Link to comment Share on other sites More sharing options...
Klez Posted October 11, 2005 Report Share Posted October 11, 2005 ja tew ir id lauks un ja vinsh ir autoincrement, tad nekaadu regdat nevaig, vien order by id desc limit 3 un bus tew peedeejie triis ieraksti :) Link to comment Share on other sites More sharing options...
Delfins Posted October 11, 2005 Report Share Posted October 11, 2005 (edited) Ir viens variants select ULP.username, max(ULP.try) AS maxtry from UserLog ULP left join UserLog ULJ ON ( ULP.username = ULJ.username AND ULJ.try = maxtry ) GROUP BY ULP.username par to AND ULJ.try = maxtry ) neesmu pārliecināts vai MYSQL atbalsta Edited October 11, 2005 by Delfins Link to comment Share on other sites More sharing options...
druidos Posted October 11, 2005 Author Report Share Posted October 11, 2005 ja tew ir id lauks un ja vinsh ir autoincrement, tad nekaadu regdat nevaig, vien order by id desc limit 3 un bus tew peedeejie triis ieraksti :) Cik esmu novērojis, izdod tos datus, kas tuvāk tabulas sākumam. Auto_increment ir. limit 3 - neder, jo ierakstu ir neierobežoti vairāk par piemērā dotajiem. Piemērā, tikai lai varētu saprast problēmu! Link to comment Share on other sites More sharing options...
druidos Posted October 11, 2005 Author Report Share Posted October 11, 2005 par to AND ULJ.try = maxtry ) neesmu pārliecināts vai MYSQL atbalsta Vismaz manējais MySQL (veca versija 2.3, jaunināt nav iespējas) tādu lietu neatbalsta. :( Link to comment Share on other sites More sharing options...
Delfins Posted October 11, 2005 Report Share Posted October 11, 2005 manuprāt bez sub-query nekā... Link to comment Share on other sites More sharing options...
Delfins Posted October 11, 2005 Report Share Posted October 11, 2005 šitais der tiaki ar PHP pre-pārsēšanu :rolleyes: mysql> select userid, max(concat(try,',',id)) as maxtry from userlog group by userid; +--------+-------------------------+ | userid | max(concat(try,',',id)) | +--------+-------------------------+ | user1 | 3,5 | | user2 | 1,2 | | user3 | 1,3 | +--------+-------------------------+ 3 rows in set (0.01 sec) while ( $row .. ) { $a = explode( ',', $row->maxtry ); $row->try = $a[0]; $row->id = $a[1]; } diezgan netriviāli, bet ja nedrīkst qub-query... Link to comment Share on other sites More sharing options...
Klez Posted October 11, 2005 Report Share Posted October 11, 2005 tas limit 3 tikai lai peedeejie 3 ieraksti. vien order by id desc .. :) Link to comment Share on other sites More sharing options...
Recommended Posts