473,756 Members | 5,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help In SQL Complex Query

crystal2005
44 New Member
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.c c/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 2454

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

Similar topics

12
2406
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 will pull out the customer details each time their is an inventory item listed....I need to get the customer out ONCE and list his items....is there an elegant way to do this: Here is the table: Cust-Invent Table
4
2021
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 mode after a certain point it give me the error message that the expression is to complex. Below is the sql code that I am using (this works so far, anything added to the code will give me the to complex error message.) SELECT .WONUM, .,...
2
1837
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 update query string in stead of using the primary key? Thanks in advance,
8
2086
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 web form when one presses the button on the web form on a client pc, the sql query which is contained in the text box is sent to a vb net application on a server pc. The win application sends the query to the database, collects the results,
1
2670
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. I wanted to execute a query which is retrieving the records from table1 by checking the condition for a long long string . I'm using where clause and checking the condition as-
4
1940
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 so I'm hoping there is a complex query that can give me the data I need. I have about 6 pages in website where I need to display a datagrid of information. There should be 5 columns, Filename, and then 4 Category Titles (These category titles...
1
2819
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 I'm trying to fix includes a form which takes entered data, concatenates it into a VB string to form an SQL query, then launches a report with information from the query. Several tables are linked in the query, but the key ones for this problem...
19
3642
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 seen sofar, is to just rewrite my code/query. Situation: I am sorting forms into the way they are used (print,storage,readonly,etc...).
5
2162
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 be 1 of these or 100....quantity can change***** </Tabs>
0
9454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10028
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9836
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9707
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6533
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3804
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2664
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.