Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Los códigos que usamos para enlazar dos bases de datos son:

SELECT
base1.*, base2.*
FROM
nombreBase1.nombreTabla base1
INNER JOIN
nombreBase2.nombreTabla base2
ON base1.id=base2.id

use Veterinaria
go

--select--
select * from Boleta
select id_boleta from Boleta
--distinct--
select distinct id_boleta from Boleta
--where--
select id_boleta from Boleta where total>120
--and or--
select id_boleta from Boleta where total>120 or (total<105 and total<96)
--in--
select * from Boleta where id_boleta in('BO-00001','BO-00002')
--between--
select * from Boleta where fecha between '2019-05-09' and '2019-05-11'
--like--
select * from Boleta where id_boleta like '%00001%'
--order by--
select id_boleta,id_cliente,total from Boleta order by 3 desc
--funciones--
--AVG--
select AVG(edad*1.0) from Paciente where sexo='M'
--COUNT--
select COUNT(apellidoPaterno) from Empleado
select COUNT(distinct cantidad) from [Detalle Boleta]
--max--
select max(edad) from Paciente
--min--
select min(edad) from Paciente
--sum--
select sum(total) from Boleta
--group by--
select id_boleta,SUM(total) from Boleta group by id_boleta
--having--
select id_boleta,SUM(total) from Boleta group by id_boleta having SUM(total)>120
--alias--
select A1.id_boleta N_Boleta,SUM(A1.total) "Total" from Boleta A1 group by
A1.id_boleta
--join--
select A1.nombres_cliente Cliente,SUM(A2.total) Total from Cliente A1, Boleta A2
group by A1.nombres_cliente
--outer join--
select A1.id_cliente Cliente,SUM(A2.total) Total from Cliente A1, Boleta A2 where
A1.id_cliente=A2.id_cliente group by A1.id_cliente
--concatenar funcion--
select CONCAT(nombres_cliente,id_cliente) from Cliente where id_cliente='CL-
00001'
select nombres_cliente + '' + id_cliente from Cliente where id_cliente='CL-00001'
--substring funcion--
select SUBSTRING(nombres_cliente,2,8) from Cliente where nombres_cliente='Roberto
Carlos'
--trim funcion--
select LTRIM('1 ejemplo 1')
select RTRIM('1 ejemplo 1')

Definir el go, cual es la finalidad de usar el go

You might also like