SQL exercises Language  September 03, 19:04 MSK
Login:

Password:

forgot password?
Registration

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

Poll
For what DBMS, besides SQL Server, you would like to have exercises on the site?
Oracle
PostgreSQL
MySQL
Another
Nothing is necessary any more



View Results
AddThis Social Bookmark Button

SQL Exercises news letters, latest issue

#309 (2010-08-28)

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 from qwrqwr have been published under number of 168 (2 points).

§
Has corrected a bug with checking the exercises:
12 (SELECT, rating stage) - data and formulation.
98 (SELECT, rating stage) - formulation from Fuddy-Duddy with correction from Fiolent and $erges
167 (SELECT, rating stage) - data from qwrqwr.
§
Changes among leaders (solved exercises of third stage):
2 Arcan (147)
5. _yizraor (158, 164)
8. MadVet (157, 158)
15. AlShin (140, 151, 166)
21. qwrqwr (168)
55. Rybka (140)
60. Baser (251, 252)
§
Have advanced in rating:
74. Johnnymnemonic (131, 258.463)
75. silver (130, 56.008)
77. risp (128, 18.003)
78. IrinkaR (127, 20.319)
84. Easy-Human (125, 10.645)
§
Applicants for Top 100 have advanced in rating:
111. count (116, 8.906)
115. Cergej L (113, 290.099)
139. aklerk (110, 92.631)
198. .Wizard (100, 555.593)
215. Fuddy-Duddy (107, 92.795)
216. GeBy (99, 8.227)
§
Have been certified last week:
Easy-Human (B10070369) [AR] - г. Оренбург, Россия
§
Statistics:
Number of subscribers - 3810
Number of rating's participants - 8851
Number of second-stage's participants - 2175
Number of third-stage's participants - 71
On the learning stage - 17518
Certified specialists in total - 455

ТОР 20

NoPersonNumber of
Sel_ex
Last_SelNumber of
DML_ex
ScoresDaysDays_2Days_3S_3LastSolvedLastVisit
1Karasyova N.V. (vlksm)1170253224091556138.49493.274832010-08-092010-08-25
2Kreslavskij O.M. (Arcan)1170253224091301143.073101.841832010-08-232010-08-26
3Sal'nikov S.A. ($erges)1169253224078928.5137.876812010-08-062010-08-27
4Zotov P.G. (Ozzy)116625322400868214.147190.281742010-07-262010-08-27
5Dubinskij A.V. (_yizraor)516525322395818215.836328.421692010-08-252010-08-27
6Yatsuk A.A. (Faust_zp)1153253223751093121.91289.835692010-02-012010-05-22
7Drozdkov A.N. (anddros)5164253223927908.6858.025662010-07-262010-08-25
8Derzhal'tsev V.A. (MadVet)7157253223701958107.49367.398592010-08-262010-08-27
9Umrikhina E.V. (Umrikhina)11402532234485341.24443.454562010-08-252010-08-25
10Bojko D.M. (Angellore)8160252223781088924.474212.056552010-07-302010-08-27
11Orlov M.V. (Eagleoff)111582532237485576.63542.990482010-08-202010-08-27
12Tarasov D.B. (Gavrila)915525122365179778.46037.300442010-07-282010-08-27
13Senkevich S.V. (GreyC)11222532130761257.71823.321382009-10-072010-01-01
14Seleznyov A.S. (Artyom S.)11192532129944447.22130.368382009-01-252009-03-03
15>Shindin A.V. (AlShin)1013416621319678204.821597.200362010-08-272010-08-27
16Nikotin V.M. (@Nikotin)1123253213044718.3353.541322009-12-112010-08-07
17Murashkin I.V. (lepton)111525121284113969.43958.709322009-05-052010-04-18
18Pechatnov V.V. (pvv)11312532131584536.96314.467282010-02-102010-08-25
19Mullakhanov R.Kh. (rem)91252532230464914.5989.679262009-06-202010-02-02
20Dvoryaninov V. (Valdaj)2015025222346421156.825161.475232010-08-112010-08-27

Best results for last week

Nosurnamen_selsel_allsel_scoresdml_scoresscoresratinglast_visit
1>Khromulyak O.M. (ChOleg)145617345158927 Aug 2010
2>Smirnov D.V. (Denni)66143448216527 Aug 2010
3>Sheringa A.A. (degluker)86513304346927 Aug 2010
4>Zhukov S.M. (__Sai)86111243557727 Aug 2010
5>Tatartseva N.A. (NeoFlora)191927734168327 Aug 2010
6Derevyankin A. (Quasar)15333203294825 Aug 2010
7>Familiya (WereWolf777)13852902929527 Aug 2010
8Luzhbin D.A. (Xordal)02702626125227 Aug 2010
9Tyul'kin M.V. (Dekart)19642502549227 Aug 2010
10>Salenko L. (kykyRyky)19602302395527 Aug 2010
11Zajtsev (andrei_az)00222227 Aug 2010
12>Bonk T.E. (Kariatida)132822022197927 Aug 2010
13Savickij A. (Venga)0102121394627 Aug 2010
14Goncharov S. (MIK_URRI)12421631974926 Aug 2010
15Pavlyk A. (Chupacabras)00171727 Aug 2010
16Sabinin O.Yu. (OCP)62910717106126 Aug 2010
17Yaremchuk (Letter)0101717503227 Aug 2010
18San'ko A.V. (count)61161601611125 Aug 2010
19Sergeev D.A. (Ethereal)14541601660127 Aug 2010
20Zryumov P.A. (Paul Clever)82410616146726 Aug 2010
21>Bublikov (John_Silver)71116016477627 Aug 2010

Let's learn SQL

FLOAT

by S.I.Moiseenko

Once in a social network was asked how to remove trailing zeros in decimal numbers. This was associated with the preparation of a report, which sums concatenate with the text. In the conditions of the problem was stated limit to two decimal places.

Here's an example of data and the desired result:

given	to obtain
0.00	0
10.00	10
2.50	2.5
100.00	100
11.33	11.33

Solutions have been proposed, based on analysis of the line. I also chose the wrong way and proposed the following solution:

SELECT num,
CASE WHEN CAST(num AS INT) = num
           THEN CAST(CAST(num AS INT) AS VARCHAR)
           WHEN CAST(num*10 AS INT) = num*10
           THEN LEFT(CAST(num AS VARCHAR), LEN(CAST(num AS VARCHAR)) - 1)
            WHEN CAST(num*100 AS INT)=num*100
            THEN CAST(num AS VARCHAR)
END fnum
FROM(
SELECT 0.00 as num
UNION ALL SELECT 10.00
UNION ALL SELECT 2.50
UNION ALL SELECT 100
UNION ALL SELECT 11.33
) X

I do not know how much it would still be continued, if one member did not notice that all problems are solved by conversion to the data type FLOAT. Really:

SELECT num, CAST(num AS FLOAT) fnum
FROM(
SELECT 0.00 as num
UNION ALL SELECT 10.00
UNION ALL SELECT 2.50
UNION ALL SELECT 100
UNION ALL SELECT 11.33
) X

However, you need to remember the approximate nature of this type, namely the magnitude of the mantissa in scientific representation of the number.

In accordance with the standard in this type of data specified argument - FLOAT (n), which can take values from 1 to 53. The SQL Server, an argument value in the range 1 - 24, interprets it as 24, which corresponds to the accuracy of 7 digits, and in the range 25 - 53 as 53, which corresponds to the accuracy of 15 digits. The default is 53.

The following example illustrates the above:

SELECT num,
CAST(num AS FLOAT(24)) num_24,
CAST(num AS FLOAT(53)) num_53
FROM(
SELECT 1234567.80 AS num
UNION ALL SELECT  12345678.90
UNION ALL SELECT 123456789012345.60
UNION ALL SELECT 1234567890123456.70
) x

num 			num_24  		num_53
1234567.80		1234568		1234567,8
12345678.90		1,234568E+07	12345678,9
123456789012345.60		1,234568E+14	123456789012346
1234567890123456.70	1,234568E+15	1,23456789012346E+15

MySQL (version 5.0)

Does not support the conversion to type FLOAT.

PostgreSQL (version 8.3.6)

Almost similar behavior, except that for the parameter in the range 1 - 24 precision is 6 digits. Accordingly, recent results will look like this:

num 			num_24  		num_53 
1234567.80		1.23457e+006	1234567.8
12345678.90		1.23457e+007	12345678.9
123456789012345.60		1.23457e+014	123456789012346
1234567890123456.70	1.23457e+015	1.23456789012346e+015

Useful links

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

§ 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-2010. All rights reserved.
contact