Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/06/2014, 20:37
rickstar
 
Fecha de Ingreso: mayo-2014
Ubicación: Tierra de Lagos y Volcanes
Mensajes: 12
Antigüedad: 10 años
Puntos: 0
Producto + Vendido

Hola, saludos a todos.

Soy nuevo en Sql, quisiera saber, cómo hacer una consulta:
1-Producto más vendido,
2-Consultar de una factura {Nombre del cliente, y del vendedor correspondiente}.
Mis datos son los siguientes:

-- #1 Tabla Productos
Create table Productos
(
Cod_Product int Primary key not null,
Nomb_Products nvarchar (50) not null,
Cantidad_Produt varchar (1000) not null,
Marca_Product nvarchar (50) not null
)

--#2 Tabla Clientes
create table Clientes
(
Cod_Cliente int Primary key not null,
Nomb_Client nvarchar (50) not null,
Apellido_Client nvarchar (50) not null,
Tele_client varchar (89) not null,
Dir_Client nvarchar (100) not null
)
--#3 Tabla Vendedores
Create table Vendedores
(
Cod_Vendedor int Primary key not null, --Primero esta tabla (Orden de definicion para que no de error en la tabla ventas)
Nomb_Vendedor nvarchar(20) not null,
Apell_Vendedor nvarchar(20) not null

)
--#4 Tabla Ventas Aqui ya no da error.
Create table Ventas
(
Cod_Vendedor int foreign key references Vendedores (Cod_Vendedor),
Cod_Product int foreign key references Productos (Cod_Product),
Fecha_Venta time not null,
Unidades_Vendidas varchar (max) not null
)

Muchas gracias.