I have three table in my database.
Customers, which contains detaills of each client, such as name, phone number ...
Products, containing detaills of each product.
each time a client requests a product, a new line is inserted in the third table Orders.
the table Orders contains the customer id (foreign key), the product id (foreign key) and the quantity desired.
what I'm looking to do is to creat a report based on the Orders table, that shows me for each Client all the Orders that he has made.
I'm working on ms access 2007.
please help me !!!
Create a query based on the orders table joined to the customer table. Use the query design window to build the query. You can then base your report on the query, using grouping to get the customer details at the top of the group and the prder details as lines within the group. Use the report wizards.
Ok I have the solution.
I created a form with this record source:
SELECT
DISTINCT Costumers.Code, Costumers.Name, Costumers.phone
FROM
Costumers INNER JOIN Orders
ON Costumers.ID=Orders.IdCostumer;
then I've created a subreport with this record source:
SELECT
[Costumers].[Code],
[Orders].[Code],
[Products].[Description],
[Orders].[Quantity]
FROM
Products INNER JOIN
(Costumers INNER JOIN Orders ON Costumers.ID=Orders.IdCostumer)
ON Products.ID=Orders.IdOrder;
and that's working the way I want.
thank you for your interest !!!
:-)
Related
I am running into an issue with writing an SQL query with Google Big Query. Basically looking to transfer the top products, per country, per category which are also in stock into a table.
So far I have pulled in the top products, per country, per category but the issue is with getting the 'in-stock' part added to the table. I can't find any similar keys in the schema to match them up.
Ideally the table would include:
Rank, Product Title, Country, Category, In-Stock
I would really appreciate any help on this! Thanks.
I have tried to add in a separate table that includes the 'availability' key for each product but I could not match it
You have your top_products table to check the rank that you can join to the product_inventory using the rank_id.
This join will retrieve the product_id and join that key to the products table.
After that, you get the availability information of the product and then you have all the information you require.
I have two tables:
A Billing table, and a Customer table.
The Billing table and customer table both share a common attribute of Customer Number.
Billing Table
I'm trying to create a view that will retrieve the customer code and bill number for the most recent invoice date. I'm having trouble ordering my query.
This is what I have so far.
CREATE VIEW RECENT_ORDER
AS
SELECT
c.Customer_Num, b.Bill_Num
FROM CUSTOMER c
INNER JOIN BILLING b ON c.Customer_Num = b.Customer_Num
WHERE c.Fname='Jess' AND c.Lname='Hanks'
HAVING MAX(b.Bill_Date);
I have also tried putting the 'HAVING' portion as a WHERE statement.
This should get your answer:
CREATE VIEW RECENT_ORDER
AS
SELECT c.customer_num, b.bill_num
FROM customer c
JOIN billing b ON c.customer_num = b.customer_num
WHERE b.bill_date =
(SELECT MAX(bill_date) FROM billing WHERE customer_num = b.customer_num)
AND c.Fname='Jess' AND c.Lname='Hanks'
Though normally I wouldn't expect to create a view that limits results to just one customer!? Remove the last line AND c.Fname ... if you intend to get the most recent result for any/all customers. Note that you may get multiple results for a customer if they have more than one invoice on the same date.
I have a database I am making with Microsoft Access 2013, where there is 2 tables. First table has productID as the primary key, second table has a unique reviewID as well as the productID of the product that the review is referring to. In first table where the products information is kept, I want to have a field that averages the ratings that it was given in it's reviews (kept in second table).
How do I average it's rating without averaging the rating for all reviews, and only for reviews about that specific product?
Based on your descriptions I've created a table called tblProducts with the following data:
I've then created a table called tblReview with the following data (here I've assumed you have a field to store a value for each review's rating that I've called ReviewRating.. and I've assumed that reviews are rated from 0-10):
I then created this query:
SELECT tblProducts.ProductName, Avg(tblReview.ReviewRating) AS AvgOfReviewRating
FROM tblReview INNER JOIN tblProducts ON tblReview.productID = tblProducts.productID
GROUP BY tblProducts.ProductName;
...which results in:
Note that this is a SELECT query, so it won't put the average review rating in to the original tblProducts table, for that you would need an UPDATE query. I wouldn't recommend that though as you'll have to remember to run the update before using tblProducts for anything that needs up-to-date averages.
I have a windows server running MS-SQL 2008.
I have a customer table that I need to select the id's of all customers that are Active, On Hold, or Suspended.
get all customers that are Y= current active customer H=on hold S=Suspended
select id from customer where active = 'Y';
the above statement worked fine for selecting the ID's of the affected customers.
I need to use these results to loop though the following command in order to find out what rates all the affected customers have.
get all rates for a customer
select rgid from custrate where custid = [loop though changing this id with results from first statement];
the id from the customer table coincides with the custid from the custrate table.
So in the end I need a list of all affected customer id's and what rgid's(rate group(s)) they have.
SQL isn't about loops in general and instead you should think in terms of joins.
select customer.id, custrate.rgid, customer.active
from customer
inner join custrate
on customer.id = custrate.custid
where active in ('Y', 'H', 'S")
order by customer.active, customer.id
would be a starting point to think about. However, that is just a wild guess as the schema was not specified nor the relations between the tables.
I have tables Products, Sales and ProductsInStores. ProductsInStores table keeps track of how many Products there are in each store. And I have a SalesProductsInStoresView with columns from tables Sales and ProductsInStores.
But there are also Products that come from a different chain of stores, so there's no ProductsInStores record for these products. So when the sale is made SalesProductsInStoresView doesn't show Sales if a Product doesn't have a ProductsInStores record.
Can I make my View show Sales with no ProductsInStores record, and just show empty cells on ProductsInStores columns, and if this is not possible what maybe other options do I have, I'm using Asp.Net MVC and Sql Server 2008.
Use Left Outer join
Select a.field1,b.field2
from tablea A
left outer join tableb b on b.fieldc = a.fieldc
this allows data to be returned from the inner table whilst maintaining a join to the outer table even if there is no data present.