SQL exercises Language  February 05, 21:01 MSK
Login:

Password:

forgot password?
Registration

Transact-SQL tests
Modelling of data
Personal
page
Exercises voting
Developers & Thanks
For employers
References
Feedback
Support SQL-EX.RU

Poll
Would you get the following certificate?
Yes
No
Such certificate is necessary on a site, but not for me
Probably I would get it for supporting the project
Such certificate is unnecessary one



View Results
AddThis Social Bookmark Button


SQL Exercises news letters, latest issue

#384 (2012-02-04)

Week news

§
As the important news can appear and between releases of news letters, I shall use this page for the publication of the information on all changes on the site.
The forum is not so suitable for this purpose since the message there "escapes" and can appear on previous page before it will lose a urgency.
So look in here if you wish to be well informed about last events on the site. The link to this page is in section of news at the main page below a subscription banner.
§
New exercises and replacements:
23 --> learn stage under number of 82
188 --> 23
188 - new exercise from qwrqwr (3 points)
189 - new exercise from Baser (4 points)
190 - new exercise from qwrqwr (1 point)
§
The most popular topics of the forum
Topic        Messages
§
Authors of the week in the forum
Author	Messages
§
Has corrected a bug with checking the exercises:
71 (SELECT, learn stage) - data from bandrey.
121 (SELECT, rating stage) - test solution and data from Pegoopik.
§
Changes among leaders (solved exercises of third stage):
8. Angellore (149, 167)
24. kalinin_k (147)
37. xLiSPirit (156)
71. GriGrim (166)
§
Have advanced in rating:
93. timka__s (134, 4.532)
§
Applicants for Top 100 have advanced in rating:
101. vavilen (128, 20.562)
112. Fuddy-Duddy (122, 115.634)
130. VSmirnov (116, 52.418)
152. smog (109, 43.998)
164. pal- (106, 4.904)
209. IrishkaS (109, 107.782)
§
Have been certified last week:
Glena4 (A12106024) [BK] - g. Lesnoj Gorodok, MO, Rossiya
Yury Egorov (B12092980) [AR] - g. Moskva, Rossiya
§
Statistics:
Number of subscribers - 3713
Number of rating's participants - 7048
Number of second-stage's participants - 2339
Number of third-stage's participants - 85
On the learning stage - 45451
Certified specialists in total - 546

ТОР 20

NoPersonNumber of
Sel_ex
Last_SelNumber of
DML_ex
ScoresDaysDays_2Days_3S_3LastSolvedLastVisit
1Yatsuk A.A. (Faust_zp)1196188234581811140.500105.7001292012-01-202012-02-03
2Kreslavskij O.M. (Arcan)1196188234581814183.319135.0031292012-01-192012-02-03
3Kurochkin P.A. (qwrqwr)119618823458801201.751141.4221292012-01-202012-02-03
4Karasyova N.V. (vlksm)1196188234582080178.664146.8611292012-01-202012-02-03
5Bezhaev A.Yu. (Baser)119518623457609144.179134.6651282012-01-012012-01-27
6Kuznetsov V.S. (herrRo)1193182234511158482.54174.0811252012-01-272012-02-02
7Sal'nikov S.A. ($erges)119018223445143111.36710.1861162012-01-272012-02-03
8Boiko D. (Angellore)81891672344016341960.3741031.6931112012-01-312012-02-03
9Shindin A.V. (AlShin)116925223407928409.211780.7681022011-05-052011-05-21
10Dubinskij A.V. (_yizraor)118017723422779284.415356.391972012-01-052012-01-30
11Tarasov D.B. (Gavrila)9180185234192295151.441106.611952011-12-122012-01-30
12Orlov M.V. (Eagleoff)9174-323407952138.753109.576942011-11-102012-02-03
13Drozdkov A.N. (anddros)51756923409127811.05310.046862011-11-282011-12-30
14Zotov P.G. (Ozzy)1170186233991376215.051190.282842011-12-312012-02-03
15Derzhal'tsev V.A. (MadVet)3159100223792073143.946101.307842010-12-292011-09-26
16Umrikhina E.V. (Umrikhina)1136672333094941.36143.454562010-11-292011-09-29
17Dvoryaninov V. (Valdaj)1716210223371898304.569314.204512011-12-222012-02-01
18Murashkin I.V. (lepton)1109162212621706122.717636.879422010-11-232010-12-03
19Filippkin D.V. (_dimon_)1816318823365109655.16950.943412012-01-212012-02-03
20Krasovskij E.A. (Pegoopik)191641882336855798.9565.919392012-02-022012-02-03

Best results for last week

Nosurnamen_selsel_allsel_scoresdml_scoresscoresratinglast_visit
1Poskonin A.V. (Andrey P)26514004062002 Feb 2012
2>Petuhov A. (APetuhov)1417201939189603 Feb 2012
3>Ivan'kov G. (IGA)233034034184203 Feb 2012
4Terent'ev S. (SunDog)003434233203 Feb 2012
5Grishin (alvigr)212131031244602 Feb 2012
6>Demidov M.V. (T-bit)1112930252203 Feb 2012
7Zhabin D. (Dmitry-89)1212829235702 Feb 2012
8>Gorodentsev A.N. (ANGorodentsev)17452602669003 Feb 2012
9Avetian A. (artemiuss)15522302360803 Feb 2012
10Sokolov A.N. (asp23)2221921301331 Jan 2012
11>Zakharov (rino spam)131319120309403 Feb 2012
12Il'ina A.B. (formatelena)001919324503 Feb 2012
13>Kukushkin S.A. (smog)61091701715203 Feb 2012
14>T E.F. (elvira10)9841701737603 Feb 2012
15Kasumov M.M. (Marat@dag05)7189817131603 Feb 2012
16Bystrov (_Joker_)8731501539602 Feb 2012
17>Shishkanova E.V. (Vred)7381231575603 Feb 2012
18>Radchenko A.S. (d3w)41251015144903 Feb 2012
19>Kudryashov V.B. (Victor_K)111215015322803 Feb 2012
20>Knyukh (Worker)6681401443203 Feb 2012

Let's learn SQL

DATEPART function and MySQL & PostgreSQL

S.I.Moiseenko

MySQL

In the MySQL dialect, each date component can be extracted from a date value with the correspondent function. Suppose we must query the Airport database to get minutes of department time of the flights that departs between 1 and 2 p.m.

Solution 1

select time_out, MINUTE(time_out)
from trip
where HOUR(time_out) = 12;

time_out               min  
1900-01-01 12:35:00    35
1900-01-01 12:00:00     0

Time components can also be got with the EXTRACT function. In this case the solution can be written in the following form:

Solution 2

select time_out, EXTRACT(MINUTE FROM time_out) AS min
from trip
where EXTRACT(HOUR FROM time_out) = 12;

The EXTRACT function can also return composite components of date and/or time, for example, year and month. Let's solve the following exercise:

Query the Paintings database to count the number of paintings in months of each year.

Solution 3

select YEAR(b_datetime) AS y, MONTH(b_datetime) AS m, EXTRACT(YEAR_MONTH FROM b_datetime) AS ym, count(*) AS qty
from utb
group by EXTRACT(YEAR_MONTH FROM b_datetime);

y     m   ym     qty
2000  1  200001  1
2001  1  200101  1
2002  1  200201  1
2002  6  200206  1
2003  1  200301  69
2003  2  200302  7
2003  3  200303  2
2003  4  200304  2
2003  5  200305  2
2003  6  200306  2
The full list of possible components can be found, for example, here.

Remark

It is appropriate to mention here rather free style of MySQL grouping. Colu9mns of a SELECT clause are allowed not to be present in the GROUP BY column list. It is obvious that an implicit aggregate function is supposed to be there, otherwise it would be impossible to interpret the statement unambiguously. I suppose that MIN or MAX functions are used implicitly but I'm not going to make it out here, because this feature contradicts SQL standard.

PostgreSQL

As far as I know, there are no functions like YEAR, MONTH, etc. in PostgreSQL. Still the EXTRACT function exists, and the second solution variant that we've written for MySQL is valid for this DBMS too.

Read more...

Useful links

§ All articles from news letters are putting on the site Books and articles about SQL thereafter.

§ We invite you to visit the Interactive SQL textbook.
    The resource is positioned as a "handbook" for this site SQL-EX.COM, but can be used irrespective of it also.

§ The following DBMS are used on the site for solving exercises: SQL Server 2008 R2 Express, MySQL 5, PostgreSQL 9.

§ If you like this site, vote for us:
del.icio.us
dzone.com
Digg.com
stumbleupon.com



| Добавить объявление - Бесплатно - купить диван недорого. Продам-куплю, б/у. |
Home
Week news
Profile
References
Rambler's Top100 KMindex Copyright SQL-EX © 2002-2012. All rights reserved.
contact