A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

New Totals Query



 
 
Thread Tools Display Modes
  #1  
Old September 19th, 2005, 01:09 AM
Jay
external usenet poster
 
Posts: n/a
Default New Totals Query

This is from famous "Northwind" DB example.

Suppose you have an Orders table that has both a Freight field and a
ShipCity field. You can create a query that displays the minimum freight cost
for orders sent to each city and it's Order ID and CustomerID.

1. Create a query that displays the minimum freight cost for orders sent to
each city. Create a new totals query, and drag the ShipCity field to the
query design grid. The Total cell beneath the ShipCity field should be set to
Group By. Drag the Freight field to the query design grid, and set the Total
cell beneath it to Min. When you run the query, it will display the minimum
freight cost for orders sent to each city. ......... How Can I put OrderID
adn CustomerID in total query design and get the result?
2. In SQL view, SELECT ShipCity, Min(Freight) AS MinOfFreight
FROM Orders GROUP BY ShipCity;
Where can I put OrderID and CustomerID in above query.

Thank you.

  #2  
Old September 19th, 2005, 01:31 AM
Duane Hookom
external usenet poster
 
Posts: n/a
Default

SELECT Orders.*
FROM Orders
WHERE Orders.OrderID In
(SELECT TOP 1 OrderID
FROM Orders O
WHERE O.ShipCity = Orders.ShipCity
ORDER BY Freight);


--
Duane Hookom
MS Access MVP


"Jay" wrote in message
...
This is from famous "Northwind" DB example.

Suppose you have an Orders table that has both a Freight field and a
ShipCity field. You can create a query that displays the minimum freight
cost
for orders sent to each city and it's Order ID and CustomerID.

1. Create a query that displays the minimum freight cost for orders sent
to
each city. Create a new totals query, and drag the ShipCity field to the
query design grid. The Total cell beneath the ShipCity field should be set
to
Group By. Drag the Freight field to the query design grid, and set the
Total
cell beneath it to Min. When you run the query, it will display the
minimum
freight cost for orders sent to each city. ......... How Can I put
OrderID
adn CustomerID in total query design and get the result?
2. In SQL view, SELECT ShipCity, Min(Freight) AS MinOfFreight
FROM Orders GROUP BY ShipCity;
Where can I put OrderID and CustomerID in above query.

Thank you.



  #3  
Old September 19th, 2005, 02:51 AM
Jay
external usenet poster
 
Posts: n/a
Default



"Duane Hookom" wrote:
Thank you. Duane.
Would you please explain your SQL query especially in :WHERE Orders.OrderID In
(SELECT TOP 1 OrderID
FROM Orders O
WHERE O.ShipCity = Orders.ShipCity
ORDER BY Freight);

SELECT Orders.*
FROM Orders
WHERE Orders.OrderID In
(SELECT TOP 1 OrderID
FROM Orders O
WHERE O.ShipCity = Orders.ShipCity
ORDER BY Freight);


--
Duane Hookom
MS Access MVP


"Jay" wrote in message
...
This is from famous "Northwind" DB example.

Suppose you have an Orders table that has both a Freight field and a
ShipCity field. You can create a query that displays the minimum freight
cost
for orders sent to each city and it's Order ID and CustomerID.

1. Create a query that displays the minimum freight cost for orders sent
to
each city. Create a new totals query, and drag the ShipCity field to the
query design grid. The Total cell beneath the ShipCity field should be set
to
Group By. Drag the Freight field to the query design grid, and set the
Total
cell beneath it to Min. When you run the query, it will display the
minimum
freight cost for orders sent to each city. ......... How Can I put
OrderID
adn CustomerID in total query design and get the result?
2. In SQL view, SELECT ShipCity, Min(Freight) AS MinOfFreight
FROM Orders GROUP BY ShipCity;
Where can I put OrderID and CustomerID in above query.

Thank you.




  #4  
Old September 19th, 2005, 04:06 AM
Duane Hookom
external usenet poster
 
Posts: n/a
Default

The criteria is a subquery that attempts to select one record from the table
where the shipcity is matched. The table in the subquery could be any table
or query.

--
Duane Hookom
MS Access MVP


"Jay" wrote in message
...


"Duane Hookom" wrote:
Thank you. Duane.
Would you please explain your SQL query especially in :WHERE
Orders.OrderID In
(SELECT TOP 1 OrderID
FROM Orders O
WHERE O.ShipCity = Orders.ShipCity
ORDER BY Freight);

SELECT Orders.*
FROM Orders
WHERE Orders.OrderID In
(SELECT TOP 1 OrderID
FROM Orders O
WHERE O.ShipCity = Orders.ShipCity
ORDER BY Freight);


--
Duane Hookom
MS Access MVP


"Jay" wrote in message
...
This is from famous "Northwind" DB example.

Suppose you have an Orders table that has both a Freight field and a
ShipCity field. You can create a query that displays the minimum
freight
cost
for orders sent to each city and it's Order ID and CustomerID.

1. Create a query that displays the minimum freight cost for orders
sent
to
each city. Create a new totals query, and drag the ShipCity field to
the
query design grid. The Total cell beneath the ShipCity field should be
set
to
Group By. Drag the Freight field to the query design grid, and set the
Total
cell beneath it to Min. When you run the query, it will display the
minimum
freight cost for orders sent to each city. ......... How Can I put
OrderID
adn CustomerID in total query design and get the result?
2. In SQL view, SELECT ShipCity, Min(Freight) AS MinOfFreight
FROM Orders GROUP BY ShipCity;
Where can I put OrderID and CustomerID in above query.

Thank you.






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query showing diff between actual and budget Bon Running & Setting Up Queries 3 August 25th, 2005 12:07 PM
Summing Totals in a query Rudi General Discussion 7 July 19th, 2005 12:36 PM
count number of records Joe_Access General Discussion 1 January 13th, 2005 06:27 PM
Totals query with an expression LMB New Users 6 November 24th, 2004 03:59 PM
Big number gives error! Sara Mellen Running & Setting Up Queries 8 October 11th, 2004 02:48 AM


All times are GMT +1. The time now is 08:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.