UNIX时间戳 按月分组 按年月分组 按日分组 mysql语句

1、按月分组:

select month(FROM_UNIXTIME(time)) from table_name group by month(FROM_UNIXTIME(time))

2、按年月分组:

select DATE_FORMAT(FROM_UNIXTIME(time),”%Y-%m”) from tcm_fund_list group by DATE_FORMAT(FROM_UNIXTIME(time),”%Y-%m”)

或者:

select FROM_UNIXTIME(time,”%Y-%m”) from tcm_fund_list group by FROM_UNIXTIME(time,”%Y-%m”)

3、按年月日分组:

select DATE_FORMAT(FROM_UNIXTIME(time),”%Y-%m-%d”) from tcm_fund_list group by DATE_FORMAT(FROM_UNIXTIME(time),”%Y-%m-%d”)

或者:

select FROM_UNIXTIME(time,”%Y-%m-%d”) from tcm_fund_list group by FROM_UNIXTIME(time,”%Y-%m-%d”)

其中FROM_UNIXTIME(time,”%Y-%m-%d”)中的time代表UNIX时间戳的字段名称

//PHP框架中写法如下
$user_list = User::group('date_name')
    ->field('FROM_UNIXTIME(create_time,"%Y-%m") as date_name,count(id) as num')
    ->select();
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇