|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Query Problem
I'm new to queries and I'm having trouble solving this problem. Here are the tables I'm working with (the name of the table is listed at the top of each).
customer +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | cust_id | int(5) | NO | PRI | NULL | | | surname | varchar(50) | YES | | NULL | | | firstname | varchar(50) | YES | | NULL | | | initial | char(1) | YES | | NULL | | | title_id | int(3) | YES | | NULL | | | address | varchar(50) | YES | | NULL | | | city | varchar(50) | YES | | NULL | | | state | varchar(20) | YES | | NULL | | | zipcode | varchar(10) | YES | | NULL | | | country_id | int(4) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | | birth_date | char(10) | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ items +----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | cust_id | int(5) | NO | PRI | NULL | | | order_id | int(5) | NO | PRI | NULL | | | item_id | int(3) | NO | PRI | NULL | | | wine_id | int(4) | NO | | NULL | | | qty | int(3) | YES | | NULL | | | price | decimal(5,2) | YES | | NULL | | +----------+--------------+------+-----+---------+-------+ orders +--------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+-------------------+-------+ | cust_id | int(5) | NO | PRI | NULL | | | order_id | int(5) | NO | PRI | NULL | | | date | timestamp | YES | | CURRENT_TIMESTAMP | | | instructions | varchar(128) | YES | | NULL | | | creditcard | char(16) | YES | | NULL | | | expirydate | char(5) | YES | | NULL | | +--------------+--------------+------+-----+-------------------+-------+ titles +----------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+----------+------+-----+---------+-------+ | title_id | int(2) | NO | PRI | NULL | | | title | char(10) | YES | | NULL | | +----------+----------+------+-----+---------+-------+ wine +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | wine_id | int(5) | NO | PRI | NULL | | | wine_name | varchar(50) | NO | MUL | NULL | | | wine_type | int(2) | NO | | NULL | | | year | int(4) | NO | | NULL | | | winery_id | int(4) | NO | MUL | NULL | | | description | blob | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ wine_type +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | wine_type_id | int(2) | NO | PRI | NULL | | | wine_type | varchar(32) | NO | | NULL | | +--------------+-------------+------+-----+---------+-------+ wine_variety +------------+--------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------+------+-----+---------+-------+ | wine_id | int(5) | NO | PRI | 0 | | | variety_id | int(3) | NO | PRI | 0 | | | id | int(1) | NO | | 0 | | +------------+--------+------+-----+---------+-------+ What I'm trying to do is find a query that lists the 10 most popular wines among customers with the title of 'Mr' where I print out the name of each wine, the type and year of each wine, and the number of customers titled 'Mr' who purchased that wine. This is what I have so far for my query, but I don't know where to go from here: select wine_name, wine_type.wine_type, year from wine, wine_type, titles where title = 'Mr' |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Query Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|