Está en la página 1de 3

*Mostrar ordenados los productos mas costosos desde el mayor hasta el de la mitad

-select top 50 percent productname, unitprice from products order by unitprice desc

*Select max(unitprice) from products group by categorid having max(unitprice) >=50


Having-

*Select upper(firtsname), lower(lastname) from employees


upper-convierte a MAY +lower-convierte todo a min

*Select left(firstname,2) NOMBRE , right(firstname, 3), substring(firstname, 3,3)


from employees
los primeros caracteres dos ultimos punto de partida en los
caracteres

*Select unitprice, floor(unitprice), ceilling(unitprice), round(unitprice,2) from


Products
aproxima hacia abajo aproxima hacia arriba redondea el decimal

*select unitprice-20, ABS(unitprice-20) from products


valor absoluto

___________________________________________________________________________________
____________________________________________________________--

1.MOSTRAR EL PRODUCTO MAS BARATO


select min(unitprice) from products

2.MOSTRAR EL PRODUCTO MAS BARATO POR PROVEEDOR Y QUE SU PRECIO NO PASE DE 30


select SupplierID, min(unitprice) group by SupplierID having <=30

3.MOSTRAR AQUELLAS PERSONAS CUYA PRIMERA LETRA ESTA INCLUIDA EN SU APELLIDO (DE DOS
MANERAS DIFERENTES)
select firstname, lastname where lastname like '%'+left(firstname,1)+'%' from
employees

4.MOSTRAR AQUELLOS PRODUCTOS CUYO PRECIO SEA ENTERO (DE DOS MANERAS DIFERENTES)
select productname, untitprice from products where unitprice = floor(unitprice)

5.MOSTRAR LA PARTE ENTERA DEL PROMEDIO DEL PRECIO UNITARIO POR CATEGORIA DE
CATEGORIAS IMPARES

6. MOStRAR EL PROMEDIO DEL PRECIO UNITARIO POR CATEGORIA REDODDEADO A UNA CIFRA
DECIMAL DE CATEGORIAS IMPARES
select round (avg(unitprice),1), categoryID from products group by categoryID
having categoryID % 2=1
7. MOSTRAR LA PARTE ENTERA DEL PROMEDIO DEL PRECIO UNITARIO POR CATEGORIA DE
CATEGORIAS PARES
select floor(avg(unitprice)), categoryID from products group by categoryID having
categoryID % 2=0

select replace(firstname, left(firstname, 1), right(firstname, 1)), firstname from


employees

sisben
cc ampliada 150
constancia
recibo
firma profesor
firma contrato

-----------------------------------------------------------------------------------
---------------------------------------------
FECHAS
DATEADD DATEDIFF DAY GETDATE MONT YEAR

select birthdate, hiredate from employees

AGREGAR UN DIA
select birthdate, dateadd(day,1,birthdate) Aumento_Fecha from employees

DIFERENCIA EN FECHAS

select birthdate, hireadate , datediff(year,birthdate, hireadate) diferencia from


emplOyees

getdate
fecha actual

___________________________________________________________________________________
_____________________________________________________

CPNVERTIR A ENTERO
select cast(unitprice as integer) from products
select cast(int, unitprice) from products

-----------------------------------------------------------------------------------
--------------------------
SUBCONSULTAS
select productname, unitprice from products where unitprice>=(slect unitprice from
products where productid=25)

MOSTRAR LOS PRODUCTOS CUYO VALOR ESTA ENTRE EL VALOR DE UN PRODUCTO Y OTRO
*select unitprice from products where unitprice between (select unitprice from
products where productid=3) and (select unitprice from products where productid=8)
MOSTAR TODAS LAS PERSONAS QUE VIVAN EN LA MISMA CIUDAD QUE UNA PERSONA DADA

select employeeID, firstname, lastname, city from employees where city = (select
city employees where employeeID=2)

MOSTRAR TODOS LOS PRODUCTOS QURE COMIENEN CON LA ULTIMA LETRA QUE TERMINAN EL
APELLIDO DE UNA PERSONA DADA

También podría gustarte