KarlisBa Posted November 2, 2009 Report Share Posted November 2, 2009 (edited) Sveiki! Ir kādas idejas kādam kā ar vienu vaicājumu varētu no MySQL db izvilkt pēc id grupējot no 1-10 ierakstus, bet teiksim 5. ierakstu parādīt kā pēdējo nevis starp 4. un 6. bet aiz 10? Slinkums rakstīt kodu, kas to aprēķinātu. :) Edited November 2, 2009 by KarlisBa Quote Link to comment Share on other sites More sharing options...
ohmygod Posted November 2, 2009 Report Share Posted November 2, 2009 Diezgan neskaidri nosacījumi. teiksim 5, bet citu reizi tev var vajadzēt 8. Tā ka taisi order_by lauku, kurā saliec atlasīšanas kārtas numurus un pēc kura kārtosi. Tā vismaz normāli cilvēki dara. Quote Link to comment Share on other sites More sharing options...
briedis Posted November 2, 2009 Report Share Posted November 2, 2009 Pameklē te: http://imthi.com/blog/programming/mysql-order-by-field-custom-field-sorting.php Quote Link to comment Share on other sites More sharing options...
KarlisBa Posted November 2, 2009 Author Report Share Posted November 2, 2009 (edited) Tas "teiksim" šoreiz bija domāts kā "tieši". Edited November 2, 2009 by KarlisBa Quote Link to comment Share on other sites More sharing options...
briedis Posted November 2, 2009 Report Share Posted November 2, 2009 Atradi atbildi dotajā saitē vai nē? Quote Link to comment Share on other sites More sharing options...
KarlisBa Posted November 2, 2009 Author Report Share Posted November 2, 2009 Guvu ideju, un jā, atradu arī beigās atbildi. Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted November 2, 2009 Report Share Posted November 2, 2009 Vispār jau nebūtu slikti arī pievienot atbildi nākotnes meklētājiem, ja citiem ievajagas :) Viens no variantiem varētu būt (numurs 3 būs tas ko likt beigās): mysql> create table x (x int); Query OK, 0 rows affected (0.11 sec) mysql> insert into x values (1), (2), (3), (4), (5); Query OK, 5 rows affected (0.05 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM x -> ORDER BY if(x=3,100,x); +------+ | x | +------+ | 1 | | 2 | | 4 | | 5 | | 3 | +------+ 5 rows in set (0.00 sec) Gints Plivna http://datubazes.wordpress.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.