Pentiums Posted January 13, 2010 Report Share Posted January 13, 2010 Sākšu ar to, ka lietotāju tabulā `draugi` glabājas vārda diena un dzimšanas diena DATE laukos (YYYY.MM.DD) un es gribu izvilkt tuvākās jubilejas, piemēram, uz nākamajām 60 dienām, tā lai parādītos šādi: dz/d 13.04 Arnis Puriņš dz/d 21.04 Jānis Bērziņš v/d 18.05 Ēriks Sietiņš dz/d 11.06 Mārtiņš Kārtiņš Es māku izvilkt tikai atsevišķi vārda dienu un dzimšanas dienu DZ/D: SELECT vards, uzvards, MONTH(dzimene) menesis, DAYOFMONTH(dzimene) diena FROM draugi WHERE DAYOFYEAR(dzimene) < '".(date('z')+60)."' V/D: SELECT vards, uzvards, MONTH(vardene) menesis, DAYOFMONTH(vardene) diena FROM draugi WHERE DAYOFYEAR(vardene) < '".(date('z')+60)."' kā šos kverijus sapludināt kopā? Quote Link to comment Share on other sites More sharing options...
endrju Posted January 13, 2010 Report Share Posted January 13, 2010 kā šos kverijus sapludināt kopā? UNION Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 13, 2010 Author Report Share Posted January 13, 2010 Labi, uzražoju šādu SELECT vards, uzvards, MONTH(dzimene) menesis, DAYOFMONTH(dzimene) diena FROM draugi UNION ALL SELECT vards, uzvards, MONTH(vardene) menesis, DAYOFMONTH(vardene) diena FROM draugi ORDER BY menesis ASC, diena ASC Tikai kā lai php pusē atšķiru kura ir vārda diena un kura dzimšanas diena? Quote Link to comment Share on other sites More sharing options...
2easy Posted January 13, 2010 Report Share Posted January 13, 2010 lai atšķirtu vai konkrētā rinda attiecas uz dzd vai vd, pieliec galā vēl vienu flag kolonnu, tipa Type SELECT vards, uzvards, MONTH(dzimene) menesis, DAYOFMONTH(dzimene) diena, 'dzd' AS Type FROM draugi WHERE DAYOFYEAR(dzimene) < '".(date('z')+60)."' UNION SELECT vards, uzvards, MONTH(vardene) menesis, DAYOFMONTH(vardene) diena, 'vd' FROM draugi WHERE DAYOFYEAR(vardene) < '".(date('z')+60)."' Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 13, 2010 Author Report Share Posted January 13, 2010 Piemetu klāt ORDER BY, vai pareizi? SELECT vards, uzvards, MONTH(dzimene) menesis, DAYOFMONTH(dzimene) diena, 'dzd' AS Type FROM draugi WHERE DAYOFYEAR(dzimene) < '".(date('z')+60)."' UNION SELECT vards, uzvards, MONTH(vardene) menesis, DAYOFMONTH(vardene) diena, 'vd' FROM draugi WHERE DAYOFYEAR(vardene) < '".(date('z')+60)."' ORDER BY menesis ASC, diena ASC Quote Link to comment Share on other sites More sharing options...
2easy Posted January 13, 2010 Report Share Posted January 13, 2010 jā, pareizi vsp jau pietiek ar to, ka pārbaudi un tas strādā ;) Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 13, 2010 Author Report Share Posted January 13, 2010 Paldies! Tagad viss notiek! :) Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 13, 2010 Author Report Share Posted January 13, 2010 Ā, un velviens jautājums. Ja ir decembra beigas un nav vairs jubilāru ko parādīt, tad vajag parādīt jubilārus no gada sākuma. Taisīt vēlvienu kveriju? Quote Link to comment Share on other sites More sharing options...
2easy Posted January 14, 2010 Report Share Posted January 14, 2010 vnk ņem tuvākās 60 dienas, nevis tuvākās šī gada 60 dienas :D Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 14, 2010 Author Report Share Posted January 14, 2010 kāda funkcija jālieto? Quote Link to comment Share on other sites More sharing options...
2easy Posted January 14, 2010 Report Share Posted January 14, 2010 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html bik paskrollējot uz leju, jau pirmais piemērs ir par laika intervālu 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.