【发布时间】:2012-05-13 11:02:14
【问题描述】:
使用 SQL,我如何为按每家公司分组的日期赋值?
当前表:
Date Company Employees
2012-04-28 Apple, Inc. 7543
2012-04-27 Apple, Inc. 7510
2012-04-26 Apple, Inc. 7484
2012-04-28 Google, Inc. 11303
2012-04-27 Google, Inc. 11300
2012-04-26 Google, Inc. 11280
2012-04-25 Google, Inc. 11278
2012-04-24 Google, Inc. 11254
所需的表:
Date company_day Company Employees
2012-04-28 3 Apple, Inc. 7543
2012-04-27 2 Apple, Inc. 7510
2012-04-26 1 Apple, Inc. 7484
2012-04-28 5 Google, Inc. 11303
2012-04-27 4 Google, Inc. 11300
2012-04-26 3 Google, Inc. 11280
2012-04-25 2 Google, Inc. 11278
2012-04-24 1 Google, Inc. 11254
company_day 的值从每个公司的最早日期开始。 company_day 是公司特定的。
【问题讨论】:
-
确定公司日的逻辑是什么?
-
@bluefeet 看起来表中最早的一天是 1,然后从那里枚举。
-
@MatthewPK 这也是我的猜测,但他们需要澄清请求