php 和 mysql 按年份和日期获取数据!表结构?

发布于 2024-12-02 08:07:55 字数 678 浏览 1 评论 0原文

在制作示例详细信息页面时,我遇到了一个非常令人困惑的情况。我真正想做的是这样的:

+----------------------------------------------------+
+ Year  | Month   | Date        | Total Gain +
+----------------------------------------------------+
+ 2003  | January | 26/01/2003  |  +90 %             + 
+ 2003  | January | 27/01/2003  |  +10 %             +   
+ 2003  | Feburary| 01/02/2003  |  -29 %             +
+ 2003  | Feburary| 15/02/2003  |  +0.52 %           +
+----------------------------------------------------+

我真正想要的是我可以列出月份名称和年份,例如 mysql_query('SELECT Month FROM mytable WHEREyear="2003"');

但是问题是它显示一月两次。我想显示一月一次,并在其旁边显示一个链接,该链接将转到下一页。这将显示一月份的统计数据。

While making a sample details page, I just stuck upon a really confusing situation. What i actually want to do is like this:

+----------------------------------------------------+
+ Year  | Month   | Date        | Total Gain +
+----------------------------------------------------+
+ 2003  | January | 26/01/2003  |  +90 %             + 
+ 2003  | January | 27/01/2003  |  +10 %             +   
+ 2003  | Feburary| 01/02/2003  |  -29 %             +
+ 2003  | Feburary| 15/02/2003  |  +0.52 %           +
+----------------------------------------------------+

What I actually want is that I can list the Month names and year wise like mysql_query('SELECT month FROM mytable WHERE year="2003"');

But the problem is it shows January two time. I want to display January one time and a link next to it which will carry to the next page. This will show the stats of January.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小伙你站住 2024-12-09 08:07:55

也许您应该使用 GROUP BY 子句并计算您的总增益。

(由于没有指定表结构,所以这里就猜测一下)

SELECT `Year`, `Month`, SUM(gain) AS 'Total Gain +' FROM table GROUP BY month, year;

Maybe you should use a GROUP BY clause and calculates your Total gain as well.

(Since the table structure is not specified, I'll guess here)

SELECT `Year`, `Month`, SUM(gain) AS 'Total Gain +' FROM table GROUP BY month, year;
作死小能手 2024-12-09 08:07:55

我认为您正在寻找的是 DISTINCT 查询,即

SELECT DISTINCT year, month FROM mytable

I think what youre looking for is DISTINCT query, ie

SELECT DISTINCT year, month FROM mytable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文