Consultas SQL para Base de Datos de Biblioteca y Muebles
Consultas SQL para Base de Datos de Biblioteca y Muebles
TAREAD
:adaaslsgiueintestabalsparaunabasededatosBIBLIOTECA
biorls
+--+----+
---+------+
-----------+---------+-----+-
id_libro
+--+----+
---+------+
-----------+---------+-----+-
C0001|Cocina
5 | a Rápida
n i c|LataKapoor|EPB
oC | 5 5 3
LasLágrimas William Hopkins
MiPrimerC++
| 0|Brian&Brooke|EPB
1 | o t x e T
C++Brainworks TDH
|F0002|Thunderbolts |AnnaRoberts|Firstpubl | 750|Fiction |50 |
+--+-----+--+
-------+----------+----------+----+
--
TABLAE
:MT
ID
IO
+---------+--------------------+
id_del_libro
+---------+--------------------+
| T0001 | 4 |
C0001 5 |
| F0001 | 2 |
+---------+--------------------+
CREARCOMANDODETABLA
CREARTABLAbilros
bo1rdchi(0_,ar)l(
nom
obreib_rdle
)02(rahcrotua_em robn>-
,)01(rahcserot ide>-
,oretneoicerp>-
,)01(rahcepyt>-
;)[Link]>-
mysql> INSERT INTO libros
,553, B E
P
' ' , ' roopK
atL
a' , 'kooctsaF' , '100C 0A V
'>L O R(-E
S
snim
kaH
poi l lW
i' , 'msairgL
ásL
a' , '1000FA
V
'L
O
sR
(oE
SrbiN
O
T
N
lE
R
T
ISI>-
P6u,F
5cb0'2óil,0n;)'
PREGUNTASDECONSULTA:
led erm
bon le rar t sM
o )a(
eodteris.
SOLUCIÓN:
e d _ e r bmo n
DEbilros
DONDEpublicadores="firstpubl";
+----------------+---------------------+-------+
nombre_del_libro precio
+--------------- +---------------------+-------+
Las lágrimas William Hopkins
Truenos 750 |
+----------------+---------------------+-------+
d serm
bon sol rat s iL )b(
SOLUCIÓN:
SELECCIONARnombre_de_lbilro
DEbilros
DONDEtipo="texto";
+--------------------+
nombre_del_libro |
+--------------------+
Mi primer c++ |
C++ Brainworks
+--------------------+
y serm
bon sol rar t sM
o )c(
SOLUCIÓN:
e d _ e r bmo n
DEbilros
ORDENARPORprecio;
+--------------------+-------+
book_name precio
+--------------------+-------+
Mi primer c++ 350
C++ Brainworks
Cocción rápida 355
Las lágrimas 650
Truenos 750
+--------------------+-------+
ed oicerp le ratnm
eA
u )a
SOLUCIÓN:
ACTUALIZARlibros
AJUSTARprecoi=precoi+50
DONDEpublicadores="EPB";
+-------+------------+
precio
+-------+------------+
405 | EPB |
400 EPB |
+-------+------------+
bi l led di rar t sM
o )e(
.odi t m
ie
SOLUCIÓN:
SELECCIONARbilrosb.ook_din,ombre_bilroC
,anditad_emdita
DEbilroesm
,dito
DONDEbooks.book_id=issued.book_id;
+---------+-----------------+---------------------+
id_del_libro
+---------+-----------------+---------------------+
C0001 | Cocción rápida | 5 |
Las lágrimas | 2 |
Mi primer c++ 4 |
+---------+----------------+----------------------+
SOLUCIÓN:
INSERTARENemdito
VALORES"(F00031";,)
+----------+-----+-
id_libro
+----------+-----+-
|T0001 | 4 |
|C0001 | 5 |
|F0001 | 2 |
F0003 1 |
+----------+-----+-
)iSELECCIONARCOUNT(*)DESDEbilros;
+------+-
CONTAR(*)
+------+-
5
+------+-
)S
iELECCIONARMAX(precoiD
) EbilrosDONDEqyt>=15;
+------+
--
|MÁX(precio)|
+------+
--
750
+------+
--
m
bon ,orbi l_erm
bonO
N
A
RIC
E
L
ES) i i i
OUTPUT
+---------+------+
--
nombre_del_libro
+---------+------+
--
CocinaRápida
Mi primer c++
+---------+------+
--
vi)SELECTCOUNT(DISTINCTedotire)FROMbilrosWHEREprecoi>=400;
+------------------+-
|CONTAR(DISTINCTpublicadores)|
+------------------+-
| 2 |
+------------------+-
PRACTICALNO:2
TAREAD
:adalsgiueinteabalESTUDIANTE
TABLAeu:stdainet
+--+--+-----+-----+
--+
-----+-+-
[Link]
+--+--+-----+-----+
--+
-----+-+-
j a k n a P
n i l a h S
121/29/6y a j n a S
a h d u S
050/9/7h s e k a R
a h S | 6 |
7
310/79/7a h k i h S
+-+
--+-----+------+--+
-----+-+-
COMANDOCREARTABLA
CREARTABLAesutdainet
,oretneN.o(>-
)02(raceNm>rob-
aretnedaE
d>-
,)02(rahctpD >e-
,ahcD>eOA-f
, regetniafirat>-
;)rahcxes>-
INSERTARENesutdainet
9/10/01 , 'arodatm
uopc' ,42 , ' jaknaP' ,AV
1>L
O
R
(-E
S
QUERYQUESTIONS
SOLUCIÓN:
SELECCIONAR*DEesutdainet
WHEREDept="historia";
+--+--+
-----+
----+--+
----+
-+
--
[Link]
+--+--+
-----+
----+--+
----+
-+
--
a h S | 2 |
a h d u S
a h S | 6 |
+--+--+
-----+
----+--+
----+
-+
--
ed erm
bon le at s iL )b(
SOLUCIÓN:
SELECCIONENombreDEesutdainet
DONDE sec = "F" y
hindi
+----+-
Nomber
+----+-
Shikha
+----+-
ed serm
bon sol arm
eunE )c(
SOLUCIÓN:
SELECCIONARnombreDEesutdainet
ORDENARPORDOA;
+---+
--
Nomber
+---+
--
Sanyj
Pankaj
Suyra
Shkiha
Rakehs
Snhial
Shakel
a h d uS
+----+-
led erm
bon le rar t sM
o )d(
SOLUCIÓN:
SELECCIONAR
DEesutdainet
DONDEsexo="M";
output
+--+
--+----+
--
Nomber
+--+
--+----+
--
Pankaj
Sanjay
Rakesh
Shakeel
Surya
+--1+-----+
--
e ed orm
eún le ratnoC )e(
SOLUCIÓN:
SELECCIONARCUENTA(*D
) Eesutdainet
DONDESexo>23;
+-----+-
CONTAR(*)
+-----+-
3 ||
+-----+-
SOLUCIÓN:
INSERTARENesutdainet
VALORES9"(Z
,ahe3"r,6c,ompuadtoa{r"1,20/39/72},30"M
, ";)
+--+--+-----+
------+--+----+
-+
--
No.
+--+--+-----+
------+--+----+
-+
--
j a k n a P
n i l a h S
121/29/6y a j n a S
a h d u S
050/9/7h s e k a R
a h S | 6 |
7
310/79/7 a h k i h S
h a Z | 9 |
+--+--+-----+
------+--+----+
-+
--
PRACTICALNO:3
TAREAD
:adaaslsgiueintestabalsparaunabasededatosDEMUEBLES
mesa
+----+-----------------+--------------+---------------+--------+-----------+
no type | DOS precio
+----+-----------------+--------------+---------------+--------+-----------+
| 1 Loto blanco cama doble 25
2 pluma rosa cuna 2002-01-20 20 |
2 delfín cuna 2002-02-19 20
4 decente mesa de oficina 30
5 zona de confort 25 |
6 donald cuna 2002-02-24 15 |
7 acabado real mesa de oficina 30 |
8 tigre real sofá 2002-02-22 30
9 asiento económico 2001-12-13 25
10 paraíso gastronómico 2002-02-02 25 |
+----+------------------+--------------+-------------- +--------+-----------+
CREARCOMANDOTABLA
INSERT INTO muebles VALORES (1, "Lirio blanco", "cama doble", '2002-02-23', 3)
0000,25);
egadlasl
+----+------------------+----------- -+--------------+---------+-----------+
no tipo DOS precio
+----+------------------+-------------+---------------+--------+-----------+
| 11 | Wood comfort | double bed | 2003-03-03 | 25 25000
| |
12 viejo zorro sofá 2003-02-20 20
13 micky cuna 15
+----+-----------------+--------------+---------------+---------+----------+
CREARTABLADECOMANDO
SOLUCIÓN
SELECCIONAR * DE muebles DONDE tipo ="cuna para bebé";
+----+--------------+----------+---------------+-------+-----------+
no DOS precio
+----+--------------+-----------+--------------+-------+-----------+
2 pluma rosa 20
3 delfín cuna 20
6 donald cuna 15 |
+----+--------------+-----------+--------------+--------+----------+
(b) listar nombre del artículo de la tabla de muebles que están por encima de 15000.
SOLUCIÓN:
SELECCIONAR itemname DE muebles DONDE precio>15000;
OUTPUT
+---------------+
itemname |
+---------------+
Loto blanco
decente |
zona de confort
acabado real
tigre real |
+----------------+
NOMBRE_DEL_ARTÍCULO
en orden descendente de nombre de artículo.
SOLUCIÓN:
SELECCIONAR nombre_del_item, tipo DE muebles DONDE DOS<'2002/01/22' ORDENAR POR nombre_del_item;
+---------------+----------------+
nombre del artículo tipo |
+---------------+----------------+
zona de confort
decente mesa de oficina
asiento económico |
pluma rosa |
+---------------+----------------+
(d) mostrar el nombre del artículo y la DOS de aquellos artículos, en los que el porcentaje de descuento es superior al 25, de
mesa de muebles.
SOLUCIÓN:
SELECCIONAR itemname, DOS DE muebles DONDE descuento > 25;
+--------------+--------------+
DOS |
+--------------+--------------+
decente 2002-01-01
acabado real
No text provided for translation.
+--------------+--------------+
SOLUCIÓN:
SELECT Count(*) FROM furniture WHERE type='sofá';
+----------+
| Contar(*) |
+----------+
| 2 |
+----------+
SOLUCIÓN:
INSERT INTO arrivals VALUES(14, "toque de terciopelo", "cama doble", '2003-03-25', 2)
5000,30);
OUTPUT
+------+----------------+---------------+---------------+--------+---------- +
no nombre del artículo DOS precio
+------+----------------+---------------+---------------+--------+-----------+
| 11 | Wood comfort | double bed | 2003-03-03 | 25000 25 | |
12 vieja zorra sofá 2003-02-20 20 |
13 micky cuna 2003-02-21 15 |
14 toque de terciopelo 30
+----+------------------+---------------+---------------+---------+-----------+