473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need Help In SQL Complex Query

crystal2005
Hi,

I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following

1. The wine name, grape variety, year, winery, and region
2. The minimum cost of wine in the inventory
3. The number of bottles available at the minimum price
4. The total number of bottles available at any price
5. The total number of unique customers who purchased the wine (at any price)
6. A breakdown of the sales revenue, stock sold, and unique customers for each price that the wine can be sol for.

So, far I have done successfully to join those queries in a single table till the fourth within one SQL query

Expand|Select|Wrap|Line Numbers
  1. SELECT wine.wine_name, grape_variety.variety, wine.year, winery.winery_name, region.region_name, inventory.cost, inventory.on_hand, SUM(inventory.on_hand) FROM wine INNER JOIN grape_variety INNER JOIN wine_variety ON wine.wine_id = wine_variety.wine_id AND wine_variety.variety_id = grape_variety.variety_id JOIN winery ON wine.winery_id = winery.winery_id JOIN region ON region.region_id = winery.region_id JOIN inventory ON inventory.wine_id = wine.wine_id GROUP BY inventory.wine_id, grape_variety.variety_id;
I have done the fifth query in a single SQL query, without having connected with the last four previous queries.

Expand|Select|Wrap|Line Numbers
  1. SELECT wine_id, COUNT(items.cust_id) from items GROUP BY wine_id;
I encountered problem to join the fifth query into the above complex query. The table rows appeared to be imbalance.

Winestore database data is available from this link, if you wish to have a look http://stevenryan.co.cc/source/other/winestore.data

Any help leading to my success to join all those six queries into a single table and in single SQL query would be appreciated. Thank you so much.
Aug 31 '08 #1
0 2430

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
4
by: ED | last post by:
I am attempting to to write a query that has a numerous nested IIf statements. The problem that I am having is that it is to long of a query to be built in design mode and when I build it in sql...
2
by: Ben de Vette | last post by:
Hi, I'm using the querybuilder when updating a record in a table (Access). However, I get a "Query is too complex" message. The Primary key is autonumbered. Why is it making such a complex...
8
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a...
1
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. ...
4
by: kyle.fitzgerald | last post by:
I'm just know basic SQL but not enough to write any complex queries. The problem I'm facing right now keeps me thinking to use a Cursor but I've seen a lot of posts on here saying Cursors are bad...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
19
by: kawaks40 | last post by:
Hi everyone :) I just recently started using access/sql. and right away I ran into this problem "SQL expression too complex" I google'd a lot on what it means, and the only workaround I've...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.