gpt4 book ai didi

php - Unixtime 和 MySQL

转载 作者:行者123 更新时间:2023-11-29 05:46:25 24 4
gpt4 key购买 nike

我的表上有一个名为 X 的字段,我存储 unixtime(php -> time())。我的问题是:

How can I list all the months from my DB, something like: 6.2009 8.2009 etc..

我的第二个问题是:

How can I make a query to list all the informations based on a month and year on the same field X(i store unixtime), I know this doesn't work, but mabe you can understand it better: where date = '06.2009'

有什么解决办法吗?

最佳答案

  • 列出所有月份:

    SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(X)) FROM MyTable;
  • 返回给定年份和月份的所有行:

    SELECT * FROM MyTable
    WHERE EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(X)) = 200906;

关于php - Unixtime 和 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com