SQL exercises Language  September 09, 09:40 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 57%
MySQL 27.8%
PostgreSQL 7.6%
Nothing is necessary any more 4%
Another 3.7%



Total Votes: 11655
 
AddThis Social Bookmark Button

SQL Exercises news letters, latest issue

#310 (2010-09-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 from new author Valday have been published under number of 169 (3 points).

§
The most popular topics of the forum
Topic        Messages
§
Changes among leaders (solved exercises of third stage):
1 Arcan (168, 169)
4. _yizraor (159, 160, 161)
8. MadVet (159)
11. Gavrila (143)
13. AlShin (156)
19. Valdaj (169)
25. mz (166)
36. Baser (140, 158)
38. Rybka (145)
§
New persons in TOP 100 or have returned (solved exercises and 2nd-stage time):
98. orange (112, 15.910)
§
Have advanced in rating:
72. Vladius (136, 34.945)
74. silver (131, 56.296)
76. IrinkaR (129, 20.544)
§
Applicants for Top 100 have advanced in rating:
112. Gendalf (111, 202.061)
123. aklerk (113, 96.603)
136. raul (108, 18.070)
156. Vendigo (98, 30.291)
167. Heromantor (96, 9.852)
186. Faust (101, 47.329)
194. Fuddy-Duddy (110, 93.385)
196. SergeyTikh (94, 14.076)
205. iljy (100, 1.814)
§
Have been certified last week:
zhuckovas (A10065917) [BK] - g. Moskva, Rossiya
Dekart (A10030622) [BK] - g. Perm', Rossiya
Ruslan1707 (A10047963) [BK] - s. Layashty, Resp. Bashkortostan , Rossiya
ChOleg (A10057837) [BK] - g. Kiev, Ukraina
§
Statistics:
Number of subscribers - 3808
Number of rating's participants - 8891
Number of second-stage's participants - 2179
Number of third-stage's participants - 71
On the learning stage - 17801
Certified specialists in total - 459

ТОР 20

NoPersonNumber of
Sel_ex
Last_SelNumber of
DML_ex
ScoresDaysDays_2Days_3S_3LastSolvedLastVisit
1>Kreslavskij O.M. (Arcan)1172169224141312144.269103.037882010-09-032010-09-03
2Karasyova N.V. (vlksm)1170253224091556138.49493.274832010-08-092010-09-03
3Sal'nikov S.A. ($erges)1169253224078928.5137.876812010-08-062010-09-03
4Dubinskij A.V. (_yizraor)416816122404826223.518336.103782010-09-022010-09-03
5Zotov P.G. (Ozzy)116625322400868214.147190.281742010-07-262010-09-03
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)7158159223731964109.10269.007622010-09-012010-09-03
9Umrikhina E.V. (Umrikhina)11402532234485341.24443.454562010-08-252010-08-25
10Bojko D.M. (Angellore)8160252223781088924.474212.056552010-07-302010-08-27
11Tarasov D.B. (Gavrila)915614322370183083.47642.315492010-08-302010-09-03
12Orlov M.V. (Eagleoff)111582532237485576.63542.990482010-08-202010-09-03
13Shindin A.V. (AlShin)1013515621321682205.435597.814382010-08-312010-09-03
14Senkevich S.V. (GreyC)11222532130761257.71823.321382009-10-072010-01-01
15Seleznyov A.S. (Artyom S.)11192532129944447.22130.368382009-01-252009-03-03
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
19Dvoryaninov V. (Valdaj)1915116922349443156.826161.475262010-09-022010-09-03
20Mullakhanov R.Kh. (rem)91252532230464914.5989.679262009-06-202010-02-02

Best results for last week

Nosurnamen_selsel_allsel_scoresdml_scoresscoresratinglast_visit
1>Tishin K.V. (plspeaker)242546046213303 Sep 2010
2Tatartseva N.A. (NeoFlora)21404204280302 Sep 2010
3>Frolov (simple09)224042042148903 Sep 2010
4Grishin (bobaaaaaaa)131330030335001 Sep 2010
5Fedorov A. (fan_1989)21532602661531 Aug 2010
6mgn Y. (yaroslavmgn_)111626026151402 Sep 2010
7>Osintsev S.V. (Sergej1986)101025025396703 Sep 2010
8Yunusov R.N. (Ruslan1707)14642032349703 Sep 2010
9Salenko L. (kykyRyky)4648152363801 Sep 2010
10>Zolotarev A.N. (Musette)106012112371203 Sep 2010
11Bublikov (John_Silver)71814923237703 Sep 2010
12Ventoso R.A. (rventoso)002222458701 Sep 2010
13>Wrobel (mawwro[PL])101020020488803 Sep 2010
14Golubev K.S. (simargl)1131720494403 Sep 2010
15Smirnov D.V. (Denni)111719019154631 Aug 2010
16>Nizamov I.K. (Nizamov)5515318535403 Sep 2010
17>Khromulyak O.M. (ChOleg)9651601647603 Sep 2010
18Sabinin O.Yu. (OCP)11401601680803 Sep 2010
19>e E.A. (gene eae)82215015288603 Sep 2010
20Familiya (WereWolf777)6921401425801 Sep 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