You are on page 1of 8

Select name,

Truncate (population/surfaceArea,2) AS people/sq.km,


If(GNP > GNPOld, Increasing, Not increasing) AS GNP Trend
From country ORDER BY name limit 10;

Select 1.1 + 2.2 = 3.3, 1.1E0 + 2.2E0 = 3.3E0;


Select 1 + 1, 1 = 1;
Select concat (abc,def,repeat(x,3));
Select abc || def;
Select qls_mode_ = pipes_as_concat;
Select abc || def;
Select Hello = hello;
Select Muller = Mueller;
Set collation_connection = latin1_german2_ci;
Select Muller = Mueller;
Select binary Hello = hello;
Select Hello = binary hello;

|
mysql> create database anthony;
mysql> use anthony;
mysql> create table people(id int primary key auto_increment,name varchar(40) no
t null default 0,age int not null default 0 );
mysql> insert into people(name,age) values( 'anthony',20);
mysql> replace into people(id,name,age) values(6,'christopher',39);
Query OK, 1 row affected (0.50 sec)
mysql> update people set age = 40;
mysql> select * from people;
mysql> update people set age = 67 where name = 'anthony';
Query OK, 1 row affected (0.17 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from people;
+----+-------------+-----+
| id | name
| age |
+----+-------------+-----+
| 1 | anthony | 67 |

| 6 | christopher | 40 |
+----+-------------+-----+
Truncante uando va ha insertar en la base de dATO los registro inicia en 1;
Con delete no inicia el regsitro e que estaba;

Existen dos tipos de join Inner join muestra la infromacion de ambas tablas;
Forma de hacer inner join coloan una coma entre cada tabla;
Select * from countrylanguage;
Select * from country;
Select code,name,language from country, countrylanguage;
Select code,name,language from country, countrylanguage
->where code = countrycode;
select c.code,c.name,co.language,ci.name
-> from country c, countrycode co, city ci
-> where c.code = co.countrycode
-> and c.code = ci.countrycode;
select c.code,c.name,co.language
from country c innner join countrycode co
on c.code = co.countrycode;
select c.code,c.name,co.language
from country c left join countrycode co
on c.code = co.countrycode;
select c.code,c.name,co.language
from country c right join countrycode co
on c.code = co.countrycode;

select count(code) from country;


select code,name from country where name=Argentina;
select code,name from country where name like ____a%;
| CHN |
| CRI |
| CYM |
| DEU |
| DNK |
| FIN |
| GHA |
| GIB |
| GRD |
| HUN |
| IND |
| IRL |
| ISL |
| JOR |
| KEN |
| LBY |
| MLT |
| NOR |
| PCN |
| PNG |
| SGP |
| SLV |
| SVK |
| SYR |
| TON |
| TWN |
| TZA |
| VUT |
| WSM |
| ZWE |
+------+
36 rows in set (0.03 sec)
mysql> select * from country where name like '____a%';
+------+------------------------+---------------+---------------------------+------------+-----------+------------+----------------+------------+------------+--------------------------------------+---------------------------------------------+--------------------------------------------+---------+-------+
| Code | Name
| Continent | Region
| Su
rfaceArea | IndepYear | Population | LifeExpectancy | GNP
| GNPOld
LocalName
| GovernmentForm
| HeadOfState
| Capital | Code2 |
+------+------------------------+---------------+---------------------------+------------+-----------+------------+----------------+------------+------------+--------------------------------------+---------------------------------------------+--------------------------------------------+---------+-------+
| ABW | Aruba
| North America | Caribbean
|
193.00 | NULL | 103000 |
78.4 | 828.00 | 793.00 |
Aruba
| Nonmetropolitan Territory of The Netherl

ands | Beatrix
| 129 | AW |
| AFG | Afghanistan
| Asia
| Southern and Central Asia |
652090.00 |
1919 | 22720000 |
45.9 | 5976.00 |
NULL |
Afganistan/Afqanestan
| Islamic Emirate
| Mohammad Omar
|
1 | AF |
| BGR | Bulgaria
| Europe
| Eastern Europe
|
110994.00 |
1908 | 8190900 |
70.9 | 12178.00 | 10169.00 |
Balgarija
| Republic
| Petar Stojanov
| 539 | BG |
| BHR | Bahrain
| Asia
| Middle East
|
694.00 | 1971 | 617000 |
73.0 | 6366.00 | 6097.00 |
Al-Bahrayn
| Monarchy (Emirate)
| Hamad ibn Isa al-Khalifa
| 149 | BH |
| BRB | Barbados
| North America | Caribbean
|
430.00 | 1966 | 270000 |
73.0 | 2223.00 | 2186.00 |
Barbados
| Constitutional Monarchy
| Elisabeth II
| 174 | BB |
| BTN | Bhutan
| Asia
| Southern and Central Asia |
47000.00 |
1910 | 2124000 |
52.4 | 372.00 | 383.00 |
Druk-Yul
| Monarchy
| Jigme Singye Wangchuk
| 192 | BT |
| CHN | China
| Asia
| Eastern Asia
| 9
572900.00 | -1523 | 1277558000 |
71.4 | 982268.00 | 917719.00 |
Zhongquo
| People'sRepublic
| Jiang Zemin
| 1891 | CN |
| CRI | Costa Rica
| North America | Central America
|
51100.00 |
1821 | 4023000 |
75.8 | 10226.00 | 9757.00 |
Costa Rica
| Republic
| Miguel ?ngel Rodrguez Echeverra
| 584 | CR |
| CYM | Cayman Islands
| North America | Caribbean
|
264.00 | NULL |
38000 |
78.9 | 1263.00 | 1186.00 |
Cayman Islands
| Dependent Territory of the UK
| Elisabeth II
| 553 | KY |
| DEU | Germany
| Europe
| Western Europe
|
357022.00 |
1955 | 82164700 |
77.4 | 2133367.00 | 2102826.00 |
Deutschland
| Federal Republic
| Johannes Rau
| 3068 | DE |
| DNK | Denmark
| Europe
| Nordic Countries
|
43094.00 |
800 | 5330000 |
76.5 | 174099.00 | 169264.00 |
Danmark
| Constitutional Monarchy
| Margrethe II
| 3315 | DK |
| FIN | Finland
| Europe
| Nordic Countries
|
338145.00 |
1917 | 5171300 |
77.4 | 121914.00 | 119833.00 |
Suomi
| Republic
| Tarja Halonen
| 3236 | FI |
| GHA | Ghana
| Africa
| Western Africa
|
238533.00 |
1957 | 20212000 |
57.4 | 7137.00 | 6884.00 |
Ghana
| Republic
| John Kufuor
| 910 | GH |
| GIB | Gibraltar
| Europe
| Southern Europe
|
6.00 |
NULL | 25000 |
79.0 | 258.00 |
NULL |
Gibraltar
| Dependent Territory of the UK
| Elisabeth II
| 915 | GI |

| GRD | Grenada
| North America | Caribbean
|
344.00 | 1974 |
94000 |
64.5 | 318.00 |
NULL |
Grenada
| Constitutional Monarchy
| Elisabeth II
| 916 | GD |
| HUN | Hungary
| Europe
| Eastern Europe
|
93030.00 |
1918 | 10043200 |
71.4 | 48267.00 | 45914.00 |
Magyarorszg
| Republic
| Ferenc Mdl
| 3483 | HU |
| IND | India
| Asia
| Southern and Central Asia | 3
287263.00 |
1947 | 1013662000 |
62.5 | 447114.00 | 430572.00 |
Bharat/India
| Federal Republic
| Kocheril Raman Narayanan
| 1109 | IN |
| IRL | Ireland
| Europe
| British Islands
|
70273.00 |
1921 | 3775100 |
76.8 | 75921.00 | 73132.00 |
Ireland/%ire
| Republic
| Mary McAleese
| 1447 | IE |
| ISL | Iceland
| Europe
| Nordic Countries
|
103000.00 |
1944 | 279000 |
79.4 | 8255.00 | 7474.00 |
?sland
| Republic
| "lafur Ragnar Grmsson
| 1449 | IS |
| JOR | Jordan
| Asia
| Middle East
|
88946.00 |
1946 | 5083000 |
77.4 | 7526.00 | 7051.00 |
Al-Urdunn
| Constitutional Monarchy
| Abdullah II
| 1786 | JO |
| KEN | Kenya
| Africa
| Eastern Africa
|
580367.00 |
1963 | 30080000 |
48.0 | 9217.00 | 10241.00 |
Kenya
| Republic
| Daniel arap Moi
| 1881 | KE |
| LBY | Libyan Arab Jamahiriya | Africa
| Northern Africa
| 1
759540.00 |
1951 | 5605000 |
75.5 | 44806.00 | 40562.00 |
Libiya
| Socialistic State
| Muammar al-Qadhafi
| 2441 | LY |
| MLT | Malta
| Europe
| Southern Europe
|
316.00 | 1964 | 380200 |
77.9 | 3512.00 | 3338.00 |
Malta
| Republic
| Guido de Marco
| 2484 | MT |
| NOR | Norway
| Europe
| Nordic Countries
|
323877.00 |
1905 | 4478500 |
78.7 | 145895.00 | 153370.00 |
Norge
| Constitutional Monarchy
| Harald V
| 2807 | NO |
| PCN | Pitcairn
| Oceania
| Polynesia
|
49.00 |
NULL |
50 |
NULL |
0.00 |
NULL |
Pitcairn
| Dependent Territory of the UK
| Elisabeth II
| 2912 | PN |
| PNG | Papua New Guinea
| Oceania
| Melanesia
|
462840.00 |
1975 | 4807000 |
63.1 | 4988.00 | 6328.00 |
Papua New Guinea/Papua Niugini
| Constitutional Monarchy
| Elisabeth II
| 2884 | PG |
| SGP | Singapore
| Asia
| Southeast Asia
|
618.00 | 1965 | 3567000 |
80.1 | 86503.00 | 96318.00 |
Singapore/Singapura/Xinjiapo/Singapur | Republic
| Sellapan Rama Nathan
| 3208 | SG |
| SLV | El Salvador
| North America | Central America
|

21041.00 |
1841 | 6276000 |
69.7 | 11863.00 | 11203.00 |
El Salvador
| Republic
| Francisco Guillermo Flores Prez
| 645 | SV |
| SVK | Slovakia
| Europe
| Eastern Europe
|
49012.00 |
1993 | 5398700 |
73.7 | 20594.00 | 19452.00 |
Slovensko
| Republic
| Rudolf Schuster
| 3209 | SK |
| SYR | Syria
| Asia
| Middle East
|
185180.00 |
1941 | 16125000 |
68.5 | 65984.00 | 64926.00 |
Suriya
| Republic
| Bashar al-Assad
| 3250 | SY |
| TON | Tonga
| Oceania
| Polynesia
|
650.00 | 1970 |
99000 |
67.9 | 146.00 | 170.00 |
Tonga
| Monarchy
| Taufa'ahau Tupou IV
| 3334 | TO |
| TWN | Taiwan
| Asia
| Eastern Asia
|
36188.00 |
1945 | 22256000 |
76.4 | 256254.00 | 263451.00 |
T'ai-wan
| Republic
| Chen Shui-bian
| 3263 | TW |
| TZA | Tanzania
| Africa
| Eastern Africa
|
883749.00 |
1961 | 33517000 |
52.3 | 8005.00 | 7388.00 |
Tanzania
| Republic
| Benjamin William Mkapa
| 3306 | TZ |
| VUT | Vanuatu
| Oceania
| Melanesia
|
12189.00 |
1980 | 190000 |
60.6 | 261.00 | 246.00 |
Vanuatu
| Republic
| John Bani
| 3537 | VU |
| WSM | Samoa
| Oceania
| Polynesia
|
2831.00 | 1962 | 180000 |
69.2 | 141.00 | 157.00 |
Samoa
| Parlementary Monarchy
| Malietoa Tanumafili II
| 3169 | WS |
| ZWE | Zimbabwe
| Africa
| Eastern Africa
|
390757.00 |
1980 | 11669000 |
37.8 | 5951.00 | 8670.00 |
Zimbabwe
| Republic
| Robert G. Mugabe
| 4068 | ZW |
+------+------------------------+---------------+---------------------------+------------+-----------+------------+----------------+------------+------------+--------------------------------------+---------------------------------------------+--------------------------------------------+---------+-------+
36 rows in set (0.00 sec)
mysql> select code from country
-> where name ='Finland';
+------+
| code |
+------+
| FIN |
+------+
1 row in set (0.00 sec)
mysql> where name ='Finland';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where

name ='Finland'' at line 1


mysql> select code from country
-> select * from country where name like '____a%';
\
mysql> select (select sum(population) from city)/
-> (select sum(population) from country) as ratio;
+--------+
| ratio |
+--------+
| 0.2352 |
+--------+
1 row in set (0.00 sec)
mysql> select c.continent,c.name,c.population from country c
-> where c.population = (select max(population) from country c1
-> where c.continent = c1.continent and population > 0);
+---------------+--------------------+------------+
| continent | name
| population |
+---------------+--------------------+------------+
| Oceania
| Australia
| 18886000 |
| South America | Brazil
| 170115000 |
| Asia
| China
| 1277558000 |
| Africa
| Nigeria
| 111506000 |
| Europe
| Russian Federation | 146934000 |
| North America | United States | 278357000 |
+---------------+--------------------+------------+

You might also like