-
Notifications
You must be signed in to change notification settings - Fork 0
/
script
154 lines (133 loc) · 3.85 KB
/
script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
1. Apresentar todas as cidades de Mato Grosso iniciadas com a letra R.
select * from
cidades c where c.estado ='MT'
AND c.nomecidade like '%r';
2. Apresentar nomes dos clientes com CPF terminados em 00.
select c.nomecliente, c.cpf
from clientes c
where c.cpf like '%00'
3. Apresentar nomes dos clientes com respectivas cidades, e veículos
adquiridos.
select cl.nomecliente, ci.nomecidade, vl.modelo
from clientes cl, cidades ci, vendas ve, veiculos vl
where cl.idcidade=ci.idcidade
and cl.idcliente=ve.idcliente
and ve.idveiculo=vl.idveiculo
4. Total de formas de pagamento utilizadas por clientes.
select fp.descricaoformapgto,count(*) total
from formaspagamento fp, vendas ve
where fp.idformaspgto=ve.idformaspgto
group by fp.descricaoformapgto
5. Total de clientes por cidades.
select ci.nomecidade, count(*) total
from clientes cl, cidades ci
where cl.idcidade=ci.idcidade
group by ci.nomecidade
6. Total de venda por mês e ano.
select to_char(v.datavenda,'DD/MM/YYYY')
from vendas v
group by to_char(v.datavenda,'MM/YYYY')
order by to_char(v.datavenda,'MM/YYYY')
7)
select fa.nomefabricante,count(*) total
from vendas vd,veiculos ve,fabricantes fa
where vd.idveiculo=ve.idveiculo
and fa.idfabricante=ve.idfabricante
group by fa.nomefabricante
8)
select ve.modelo,to_char(vd.datavenda,'MM') mes,count(*) total
from veiculos ve,vendas vd
where vd.idveiculo=ve.idveiculo
group by ve.modelo,to_char(vd.datavenda,'MM')
9)
select ve.nomevendedor,count(*) t
from vendas vd,vendedores ve
where vd.idvendedor=ve.idvendedor
group by ve.nomevendedor
10)
select ci.nomecidade,count(*) t
from vendas vd,cidades ci, clientes cl
where vd.idcliente=cl.idcliente
and ci.idcidade=cl.idcidade
group by ci.nomecidade
11)
select cl.nomecliente,count(*) total
from clientes cl,vendas ve
where cl.idcliente=ve.idcliente
group by cl.nomecliente
having count(*)=
(
select max(tabela.total) from (
select vd.idcliente,count(*) total
from vendas vd
group by vd.idcliente) tabela)
12)
Apresentar os clientes que realizaram as maiores compras "valor(es)" [Soma de valores].
select cn.nomecliente,sum(vc.valor)
from vendas vn,clientes cn,veiculos vc
where vn.idcliente=cn.idcliente
and vn.idveiculo=vc.idveiculo
group by cn.nomecliente
having sum(vc.valor)=
(
select max(somas.v) from
(select ve.idcliente,sum(vl.valor) v
from veiculos vl,vendas ve
where vl.idveiculo=ve.idveiculo
group by ve.idcliente) somas)
13) Apresentar nomes de clientes agrupados pelo primeiro nome.
select substring(cl.nomecliente,1,position(' ' in cl.nomecliente)),count(*) total
from clientes cl
group by substring(cl.nomecliente,1,position(' ' in cl.nomecliente))
14) Total de vendas por cidade da revenda.
select c.nomecidade, count(*) total
from revendas r, vendas v, cidades c
where r.idcidade=c.idcidade
and r.idrevenda=v.idrevenda
group by c.nomecidade
15.Apresentar todos os clientes e revendas Mato Grosso na mesma
sentença
select cl.nomecliente
from clientes cl, cidades ci
where cl.idcidade = ci.idcidade
and ci.estado = 'SP'
union
select re.nomerevenda
from revendas re, cidades ci
where re.idcidade=ci.idcidade
and ci.estado='SP'
16)
select ve.modelo,count(*) quantidade
from veiculos ve,vendas vd
where ve.idveiculo=vd.idveiculo
group by ve.modelo
17)
select ve.idveiculo,ve.modelo
from veiculos ve
where
ve.idveiculo not in
(select vd.idveiculo
from vendas vd)
18)
select vl.modelo,vd.datavenda
from veiculos vl,vendas vd
where vl.idveiculo=vd.idveiculo
and vd.datavenda = (select min(ve.datavenda)
from vendas ve)
19)
select fa.nomefabricante,count(*) TotalFabricantes
from veiculos ve,fabricantes fa
where ve.idfabricante=fa.idfabricante
group by fa.nomefabricante
20)
select ve.modelo,ve.potenciahp
from veiculos ve
where ve.potenciahp = (
select max(vl.potenciahp)
from veiculos vl)
21)
select cl.nomecliente,cl.cpf
from clientes cl,vendas vd
where cl.idcliente=vd.idcliente
and vd.datavenda=(select min(ve.datavenda)
from vendas ve)