[redes] Re: SQL 30-10

  • From: Luana Meurer <luameu@xxxxxxxxx>
  • To: grupo de e-mail faculdade <redes@xxxxxxxxxxxxx>
  • Date: Wed, 30 Oct 2013 11:57:28 -0200

Atenciosamente,
Luana Meurer


Em 30 de outubro de 2013 11:54, Luana Meurer <luameu@xxxxxxxxx> escreveu:

> Oi amigos da rede globo
> jajá envio meus sql's
>
> Atenciosamente,
> Luana Meurer
>
>
> Em 30 de outubro de 2013 09:42, Gustavo O Ph <gustavoph80@xxxxxxxxx>escreveu:
>
> select (vtc.cod_cidade) as "Código Cidade",
>>   upper(vtc.nome_cidade) as "Cidade",
>>   vte.cod_estado as "Código Estado",
>>   upper(vte.nome_estado) as "Estado"
>>
>> from vtcidade vtc
>>
>> join vtestado vte on vte.cod_estado = vtc.cod_estado
>>
>> where (vtc.cod_cidade > 10 and vtc.cod_cidade < 50)
>> and   (vtc.nome_cidade like '%a%')
>> and   (vte.nome_estado not like 'Santa Catarina')
>> order by (vtc.cod_cidade) asc
>>
>>
>> Em 30 de outubro de 2013 09:27, Gustavo O Ph <gustavoph80@xxxxxxxxx>escreveu:
>>
>> where (vtc.cod_cidade > 10 and vtc.cod_cidade < 50)
>>> and    vtc.nome_cidade like '%a%'
>>> order by vtc.cod_cidade asc
>>>
>>>
>>> Em 30 de outubro de 2013 09:26, Gustavo O Ph 
>>> <gustavoph80@xxxxxxxxx>escreveu:
>>>
>>> ex.5
>>>>
>>>> select (vtc.cod_cidade) as "Código Cidade",
>>>>   upper(vtc.nome_cidade) as "Cidade",
>>>>   vte.cod_estado as "Código Estado",
>>>>   vte.nome_estado as "Estado"
>>>>
>>>> from vtcidade vtc
>>>>
>>>> join vtestado vte on vte.cod_estado = vtc.cod_estado
>>>>
>>>> where (vtc.cod_cidade > 10 and vtc.cod_cidade < 50)
>>>> and    vtc.nome_cidade like '%a%'
>>>> order by vtc.cod_cidade asc
>>>>
>>>>
>>>> Em 30 de outubro de 2013 09:00, Gustavo O Ph 
>>>> <gustavoph80@xxxxxxxxx>escreveu:
>>>>
>>>>> select (vtc.cod_cidade) as "Código",
>>>>>   upper(vtc.nome_cidade) as "Cidade"
>>>>>
>>>>> from  vtcidade vtc
>>>>>
>>>>> where (vtc.cod_cidade > 10 and vtc.cod_cidade < 50)
>>>>> and    vtc.nome_cidade like '%a%'
>>>>> order by vtc.cod_cidade asc
>>>>>
>>>>>
>>>>>
>>>>> Em 30 de outubro de 2013 09:00, Gustavo O Ph 
>>>>> <gustavoph80@xxxxxxxxx>escreveu:
>>>>>
>>>>> CORREÇÃO:
>>>>>> Ordenar por cod e não nome
>>>>>>
>>>>>>
>>>>>>
>>>>>> Em 30 de outubro de 2013 08:59, Gustavo O Ph 
>>>>>> <gustavoph80@xxxxxxxxx>escreveu:
>>>>>>
>>>>>> 1 ao 4
>>>>>>>
>>>>>>> select (vtc.cod_cidade) as "Código",
>>>>>>>   upper(vtc.nome_cidade) as "Cidade"
>>>>>>>
>>>>>>> from  vtcidade vtc
>>>>>>>
>>>>>>> where (vtc.cod_cidade > 10 and vtc.cod_cidade < 50)
>>>>>>> and    vtc.nome_cidade like '%a%'
>>>>>>> order by vtc.nome_cidade asc
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Join
associação de várias tabelas
Sintaxe:
from <primeira tabela> <tipo join> <segunda tabela> ON <condição> Pk = fk

1. Codigo das cidades e seus respectivos nomes, no caso que os codigos das 
cidades sejam maiores que 10 e menores que 50. Ordene por codigo ascendente. 
VTCIDADE

select cid.cod_cidade,
       cid.nome_cidade
from vtcidade cid
where cid.cod_cidade > 10
and cid.cod_cidade < 50
order by cid.cod_cidade asc

2. Quantos registros?
3. A seleção deverá ser apresentada em caixa alta (nome_cidade)
4. Mostrar apenas as cidades que contenham 'a' em parte de seu nome

select upper (cid.nome_cidade),
              cid.cod_cidade
from vtcidade cid
where cid.cod_cidade > 10
and   cid.cod_cidade < 50
and   cid.nome_cidade like '%a%'
order by cid.cod_cidade asc

5. No mesmo SQL, traga o código do estado e seu respectivo nome

select upper (cid.nome_cidade),
              cid.cod_cidade,
              uf.cod_estado,
              uf.nome_estado
from vtcidade cid join vtestado uf ON uf.cod_estado = cid.cod_estado
where cid.cod_cidade > 10
and   cid.cod_cidade < 50
and   cid.nome_cidade like '%a%'
order by cid.cod_cidade asc


6. Quais são as cidades que não fazem parte do estado de Santa Catarina?
7. Quais e quantas são?

select upper (cid.nome_cidade),
              cid.cod_cidade,
              uf.cod_estado,
              uf.nome_estado
from vtcidade cid
join vtestado uf ON uf.cod_estado = cid.cod_estado
where cid.cod_cidade > 10
and   cid.cod_cidade < 50
and   cid.nome_cidade like '%a%'
and   uf.nome_estado not like 'Santa Catarina'
order by cid.cod_cidade asc

Other related posts: