View Single Post
Old 11-26-2012, 11:50 PM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,247
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Great. Now just what is it you want to display, GIVEN that sample data??

*********

Just to demo the concept, here's my sample data:
Code:
mysql> select * from prod;
+------------+-----------+-------+
| prodgroup  | product   | price |
+------------+-----------+-------+
| television | rca       |   430 |
| television | lg        |   388 |
| microwave  | panasonic |   158 |
| microwave  | amana     |   138 |
| microwave  | ge        |   169 |
| television | sony      |   478 |
+------------+-----------+-------+
And then here is the query I used:
Code:
mysql> select p.prodgroup, p.product, p.price, m.lowest
    -> from prod as p, ( 
    ->      select prodgroup, min(price) as lowest from prod group by prodgroup 
    -> ) AS m
    -> where p.prodgroup = m.prodgroup
    -> order by prodgroup, product, price;
to produce this output:
Code:
+------------+-----------+-------+--------+
| prodgroup  | product   | price | lowest |
+------------+-----------+-------+--------+
| microwave  | amana     |   138 |    138 |
| microwave  | ge        |   169 |    138 |
| microwave  | panasonic |   158 |    138 |
| television | lg        |   388 |    388 |
| television | rca       |   430 |    388 |
| television | sony      |   478 |    388 |
+------------+-----------+-------+--------+
So... a list of everything in the "group" (what you were calling "tag"), ordered by price, and showing IN EACH ROW the lowest price in the group.

Not sure that's exactly what you want, and of course it doesn't relate all that well to the expedia data, but the point is that you can do everything in a single query.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote