- 论坛徽章:
- 0
|
如果想放到一句的话
mysql> select a.work_id,a.prod_date as max_date,a.prod_num as max_num,b.prod_date as min_date,b.prod_num as min_num from (select * from table_name as a where a.prod_num = (select max(prod_num) from table_name where work_id = a.work_id
)) as a,(select * from table_name as a where a.prod_num = (select min(prod_num) from table_name where work_id = a.work_id )) as b where a.work_id = b.work_id;
+---------+------------+---------+------------+---------+
| work_id | max_date | max_num | min_date | min_num |
+---------+------------+---------+------------+---------+
| 3396 | 2008-01-04 | 132 | 2008-01-03 | 123 |
| 3397 | 2008-01-04 | 77 | 2008-01-03 | 43 |
+---------+------------+---------+------------+---------+
2 rows in set (0.00 sec) |
[ 本帖最后由 yueliangdao0608 于 2008-2-27 15:13 编辑 ] |
|