shurix Posted April 17, 2008 Report Share Posted April 17, 2008 Es sarindoju visu pec id desc un kā vareetu izskatities query ja man vajag izveleties visu iznemot pedejo ierakstu? Link to comment Share on other sites More sharing options...
andrisp Posted April 17, 2008 Report Share Posted April 17, 2008 (edited) Moška nav labākais variants, bet strādā: SELECT * FROM table WHERE id != (SELECT MIN(id) FROM table) ORDER BY id DESC Edited April 17, 2008 by andrisp Link to comment Share on other sites More sharing options...
Aleksejs Posted April 17, 2008 Report Share Posted April 17, 2008 Pieņemsim, ka vaicājums ir: SELECT id FROM tabula ORDER BY id DESC Tādā gadījumā viens no veidiem: SELECT id FROM tabula WHERE id NOT IN (SELECT id FROM tabula ORDER BY id ASC LIMIT 1 ) ORDER BY id DESC Link to comment Share on other sites More sharing options...
andrisp Posted April 17, 2008 Report Share Posted April 17, 2008 Aleksej, vai ir jēga no NOT IN, ja subkverijs tikai vienu vērtību vienmēr atgriezīs ? :) Link to comment Share on other sites More sharing options...
shurix Posted April 17, 2008 Author Report Share Posted April 17, 2008 Moška nav labākais variants, bet strādā: SELECT * FROM table WHERE id != (SELECT MIN(id) FROM table) ORDER BY id DESC Paldies Link to comment Share on other sites More sharing options...
PheliX Posted April 17, 2008 Report Share Posted April 17, 2008 Unsupported subquery syntax: ERROR 1235 (ER_NOT_SUPPORTED_YET) SQLSTATE = 42000 Message = "This version of MySQL does not yet support 'LIMIT & IN/ALL/ANY/SOME subquery'" This means that statements of the following form do not work yet: SELECT * FROM t1 WHERE s1 IN (SELECT s2 FROM t2 ORDER BY s1 LIMIT 1) http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html Link to comment Share on other sites More sharing options...
shurix Posted April 17, 2008 Author Report Share Posted April 17, 2008 Velviens mazinsh jautaajums. Es te mocos lai uztaisitu arhivu sadalu. Datubaze ir saglabati ieraksti ar datumiem 2008-04-16 10:07:55 2008-04-16 20:51:30 2008-04-17 17:16:20 Ka es vareetu izveidot ta lai no datubazes izvaditu shaja gadijuma tikai 2008-04-16 2008-04-17 tatad ja ir vairaki ieraksti taja diena tad nem vera tikai vienu. Meginaju ar DISTINCT bet neizdevas jo vinsh nem vera arii laiku netikai dienu. Link to comment Share on other sites More sharing options...
andrisp Posted April 17, 2008 Report Share Posted April 17, 2008 (edited) SELECT DISTINCT FUNKCIJA_KAS_IZGRIEZH_DATUMU(datuma_lauks); google: date and time functions mysql Edited April 17, 2008 by andrisp Link to comment Share on other sites More sharing options...
shurix Posted April 17, 2008 Author Report Share Posted April 17, 2008 Atradu tas visas funkcijas bet kaut ka nekas neiekrita acis. PAmeginaju ar explode bet ar nekas labs nesanaca :( To pashu pirmo query vajadzet apvienot ar sho. Lai nenem vera pedejo ierakstu un vel atlasa tikai tos kas nav vienadi pec datuma nevis laika kaut ari laukaa ir gan datums gan laiks. Pasham laikam smadzenes pa iisu kaut ko taadu izdomaat :( Link to comment Share on other sites More sharing options...
andrisp Posted April 17, 2008 Report Share Posted April 17, 2008 http://dev.mysql.com/doc/refman/5.0/en/dat...l#function_date Link to comment Share on other sites More sharing options...
Aleksejs Posted April 17, 2008 Report Share Posted April 17, 2008 Un Tev tie datumlaiki tā kā teksts glabājas? Link to comment Share on other sites More sharing options...
Aleksejs Posted April 17, 2008 Report Share Posted April 17, 2008 (edited) Aleksej, vai ir jēga no NOT IN, ja subkverijs tikai vienu vērtību vienmēr atgriezīs ? :) Manuprāt ir jēga, jo nevienmēr varēsi ar min max izlīdzēties. Iedomājies tabula grāmatas, kurā ir id un nosaukums. vajag atgriezt visas izņemot pēdējo alfabetiski. Tad mans variants nostrādātu (cik saprotu, tad ne visās versijās) ar: SELECT g1.nosaukums FROM gramatas AS g1 WHERE g1.id NOT IN (SELECT g2.id FROM gramatas ORDER BY nosaukums DESC LIMIT 1 ) ORDER BY nosaukums ASC vēl var arī šādi ar MySQLā definētu mainīgo (cerams, ka sintaksi no galvas pareizi uzrakstīšu, bet nu idejiski): @a:=SELECT count(id) FROM gramatas; SELECT nosaukums FROM gramatas ORDER BY nosaukums LIMIT 0 , @a-1 Edited April 17, 2008 by Aleksejs Link to comment Share on other sites More sharing options...
andrisp Posted April 17, 2008 Report Share Posted April 17, 2008 Aleksej, bet SELECT g2.id FROM gramatas ORDER BY nosaukums DESC LIMIT 1 tāpat taču atgriezīs tikai vienu vērtību. Link to comment Share on other sites More sharing options...
shurix Posted April 17, 2008 Author Report Share Posted April 17, 2008 (edited) Un Tev tie datumlaiki tā kā teksts glabājas? Datums glabajas "datetime". SELECT DATE('datums') FROM bildes WHERE id != (SELECT MAX(id) FROM bildes) ORDER BY id DESC Kaut kas sheit nav pareizs laikam? Edited April 17, 2008 by shurix Link to comment Share on other sites More sharing options...
Aleksejs Posted April 18, 2008 Report Share Posted April 18, 2008 Andri, tādēļ, ka: 1. MySQL nezin, ka vaicājums atgriezīs tikai vienu rezultātu, tādēļ kliegs, ka nedrīkst rakstīt = vai <> 2. Varbūt savajagās, ka neatgriež pēdējos 5 - tādā gadījumā vaicājums nebūs jāmaina (tikai subquery atgrieztais skaits). Link to comment Share on other sites More sharing options...
Recommended Posts