mysql取最新更新问题
有tab1,有3列
货物名称,今天到多少,顺序
goodname,arrival_t,order
gd1,30,1
gd1,40,2
gd1,50,3
gd2,10,1
gd2,11,2
gd3,1,1
gd3,12,2
我要取排序最大的gd,取出来的结果集应该是这样的
gd1,50,3
gd2,11,2
gd3,12,2
不知道mysql用一条语句怎么取,oracle可以用分区排序后取,mysql好像没这个函数
SQL code:
select * from tab1 t
where not exists
(select 1 from tab1 where goodname=t1.goodname and arrival_t>t.arrival_t);
SQL code:
mysql> select * from tab1;
+----------+-----------+-------+
| goodname | arrival_t | order |
+----------+-----------+-------+
| gd1 | 30 | 1 |
| gd1 | 40 | 2 |
| gd1 | 50 | 3 |
| gd2 | 10 | 1 |
| gd2 | 11 | 2 |
| gd3 | 1 | 1 |
| gd3 | 12 | 2 |
+----------+-----------+-------+
7 rows in set (0.00 sec)
mysql> select a.*
-> from tab1 a inner join (
-> select goodname,max(`order`) as max_order
-> from tab1
-> group by goodname
-> ) b on a.goodname=b.goodname and a.order=b.max_order;
+----------+-----------+-------+
| goodname |
相关问答:
如题,这三个在win7下使用会有什么兼容性问题吗?
由于我最近在使用win7,就懒得进xp了!
自己用windows 2008有一年多了,没出现任何问题。
win7测试版也用过,不会有什么问题的,放心。
当然你最 ......
Winform+MySQL做项目,在注重性能的情况下,我该如何去完成这类型的项目呢!
请各位给以提示。
你这个范围太广了,我说2点重要的吧
1.WINFORM程序是单独运行的CS程序,和BS不同,BS的压力始终都在SERVER上的,对C ......
我以前安装了一次,后来卸载了,现在再安装的时候,提示错误:Error 1305.Error reading from file C:DOCUME~1\LOCALS~1\Temp\mysql_server.msi.Verify that the file exists and that you can access it.
可是我找 ......
我用的like模糊查询,比如mysql的name中有“csdn论坛系统”这几个字,如何在 <input>中查询“csdn 系统”也能出来这个“csdn论坛系统”,我现在是查“csdn”或者“系统”都可以。谢谢各位了!不知道我这么表达 ......
在三十讲遇到这样一个问题就是运行代码时出现错误 Fatal error: Call to undefined method mysql::fetch_array() in D:\WWW\news\index.php on line 12
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现F ......