使用带有datagridview的Max函数

时间:2014-02-03 18:33:16

标签: mysql vb.net

我有一个装满机器订单的数据库。当机器订单发生变化时,修订级别会发生变化,从0,1,2,......开始。

我有同事的MySql陈述:

"SELECT reference as ""Reference"", serial_number as ""Serial Number"", revision as ""Revision"", Model as ""Model"" FROM `configurator`.`final_order` WHERE shipped = '0' GROUP by serial_number"

我也试过了:

"SELECT reference as ""Reference"", serial_number as ""Serial Number"", MAX(revision) as ""Revision"", Model as ""Model"" FROM `configurator`.`final_order` WHERE shipped = '0' GROUP by serial_number"

这只是给了我该序列号的最大修订版,但返回了第一个条目的所有数据,而不是最后一个修订条目。

我的数据库有数百个条目,我想填充一个datagridview,其中所有条目按序列号分组,但只显示具有最高版本的序列号条目。我希望这是有道理的。

非常感谢任何帮助。

谢谢

1 个答案:

答案 0 :(得分:0)

我不确定你想要什么,但也许是这个:

SELECT reference as ""Reference"", serial_number as ""Serial Number"", revision as ""Revision"", Model as ""Model"" 
FROM configurator.final_order 
WHERE revision = MAX(revision) AND shipped = '0' 
GROUP by serial_number