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 |
相关问答:
我现在学习MYSQL,问下mysql储存过程如何建立和使用,最好写成$sql="sql语句",$re=mysql_query($sql);谢谢
建议你先自己看一下文档中的例子。
http://dev.mysql.com/doc/refman/5.1/zh/stored-pro ......
我有一个java环境下的程序,在本机运行正常,但发布到网的虚拟主机时不能连接数据库连接池
jdk 1.6 tomcat6.0.18 mysql5 mysqljdbc5.1.5
虚拟主机的技术人员说,只能配置局域的数据库连接池,也就是在M ......
我以前安装了一次,后来卸载了,现在再安装的时候,提示错误: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.
可是我找 ......
在三十讲遇到这样一个问题就是运行代码时出现错误 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 ......
我用的是MySQL Server5.0绿色版的,我给它开了3506端口
在有些计算机上,过没多久它就会自动关闭,但有些计算机上又不会
这个问题该怎么处理啊?
cmd --> F:\MySql\MySqlServer5.1\bin\mysqld --i ......