help with query

This is a discussion on help with query within the MySQL Database forums, part of the Database Forums category; Hi, I need help in writing a query. The following query uses 2 tables and my try is pasted below; ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-25-2007
ros
 
Posts: n/a
Default help with query

Hi,

I need help in writing a query.

The following query uses 2 tables and my try is pasted below; I don't
understand how to use count, max functions here.

"return the name of the airport with the most flights departing from
it. Only return one row and one column of data."

select a.name
from flight_profiles f, airports a
where f.flt_from = a.iata_code
and f.flt_from
order by f.flt_from DESC
LIMIT 1;

CREATE TABLE `my-database`.`airports` (
`IATA_CODE` varchar(3) default NULL,
`NAME` varchar(30) default NULL,
`CTY_IATA_CODE` varchar(3) default NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `my-database`.`flight_profiles` (
`FLP_ID` decimal(8,0) default NULL,
`FLT_NUMB` decimal(4,0) default NULL,
`SEATS` int(11) default NULL,
`PRICE_CODE` varchar(3) default NULL,
`FLT_FROM` varchar(3) default NULL,
`FLT_TO` varchar(3) default NULL,
`depart` datetime default NULL,
`arrive` datetime default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Thanks in advance.
ros

Reply With Quote
  #2 (permalink)  
Old 04-25-2007
lark
 
Posts: n/a
Default Re: help with query

== Quote from ros (ros060@gmail.com)'s article
> Hi,
> I need help in writing a query.
> The following query uses 2 tables and my try is pasted below; I don't
> understand how to use count, max functions here.
> "return the name of the airport with the most flights departing from
> it. Only return one row and one column of data."
> select a.name
> from flight_profiles f, airports a
> where f.flt_from = a.iata_code
> and f.flt_from
> order by f.flt_from DESC
> LIMIT 1;
> CREATE TABLE `my-database`.`airports` (
> `IATA_CODE` varchar(3) default NULL,
> `NAME` varchar(30) default NULL,
> `CTY_IATA_CODE` varchar(3) default NULL,
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
> CREATE TABLE `my-database`.`flight_profiles` (
> `FLP_ID` decimal(8,0) default NULL,
> `FLT_NUMB` decimal(4,0) default NULL,
> `SEATS` int(11) default NULL,
> `PRICE_CODE` varchar(3) default NULL,
> `FLT_FROM` varchar(3) default NULL,
> `FLT_TO` varchar(3) default NULL,
> `depart` datetime default NULL,
> `arrive` datetime default NULL
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
> Thanks in advance.
> ros


this is relatively simple:
select name from airports join flight_profiles on flt_from = iata_code group by
iata_code order by count(iata_code) desc limit 1;

hope this helps
Reply With Quote
  #3 (permalink)  
Old 04-26-2007
ros
 
Posts: n/a
Default Re: help with query

On Apr 25, 2:41 pm, lark <ham...@sbcglobal.net> wrote:
> == Quote from ros (ros...@gmail.com)'s article
>
>
>
> > Hi,
> > I need help in writing a query.
> > The following query uses 2 tables and my try is pasted below; I don't
> > understand how to use count, max functions here.
> > "return the name of the airport with the most flights departing from
> > it. Only return one row and one column of data."
> > select a.name
> > from flight_profiles f, airports a
> > where f.flt_from = a.iata_code
> > and f.flt_from
> > order by f.flt_from DESC
> > LIMIT 1;
> > CREATE TABLE `my-database`.`airports` (
> > `IATA_CODE` varchar(3) default NULL,
> > `NAME` varchar(30) default NULL,
> > `CTY_IATA_CODE` varchar(3) default NULL,
> > ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
> > CREATE TABLE `my-database`.`flight_profiles` (
> > `FLP_ID` decimal(8,0) default NULL,
> > `FLT_NUMB` decimal(4,0) default NULL,
> > `SEATS` int(11) default NULL,
> > `PRICE_CODE` varchar(3) default NULL,
> > `FLT_FROM` varchar(3) default NULL,
> > `FLT_TO` varchar(3) default NULL,
> > `depart` datetime default NULL,
> > `arrive` datetime default NULL
> > ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
> > Thanks in advance.
> > ros

>
> this is relatively simple:
> select name from airports join flight_profiles on flt_from = iata_code group by
> iata_code order by count(iata_code) desc limit 1;
>
> hope this helps


Thanks Lark for the help. Really appreciate that.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0