gpt4 book ai didi

php - 按季度分组年度

转载 作者:行者123 更新时间:2023-11-29 06:55:13 24 4
gpt4 key购买 nike

我需要在我的 .php 文件中按年按季度分组。在 bold 类型中,我显示了需要修复的代码,也就是 switch case 4。刚才我对年、月、周和日进行了分组,但现在我需要季度名称 case 4。我试过了GROUP FUNCTION 的代码,但在 2010 年和 2011 年向我展示了 5 个组,这是错误的。

switch ($level) 
{

case '4':**
$group = "FLOOR(EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(invoice_date))/3)";</b>
break;
}

固定是

SQL PARTcase '4':                    $group = "EXTRACT(YEAR FROM FROM_UNIXTIME(invoice_date)) as group_field2, EXTRACT(QUARTER FROM FROM_UNIXTIME(invoice_date))";                    break;    $sql_select = $db->query("SELECT sum(amount) AS invoice_amount, " . $group . " AS group_field FROM                 " . DB_PREFIX . "invoices WHERE invoice_date>= " . $startup . " " . $user_query . " GROUP BY group_field, group_field2 ORDER BY group_field2 DESC, group_field DESC");TEXT - LINK PART                    case '4':                        $start = strtotime('+' . (($view_details_received['group_field'] - 1) * 3) . ' months', strtotime($view_details_received['group_field2'] . '/1/1'));                        $finish = strtotime('+' . (($view_details_received['group_field'] - 1) * 3 + 3) . ' months', strtotime($view_details_received['group_field2'] . '/1/1'));                        $start = getdate($start);                        $finish = getdate($finish - 86400);                        $title = 'Q' . $view_details_received['group_field2'] . ', ' . $view_details_received['group_field'];                        break;

最佳答案

您可以在 SQL 中使用 EXTRACT(QUARTER FROM date) 然后进行常规 GROUP BY

参见 EXTRACT documentation在 MySQL 网页和 table of possible arguments

关于php - 按季度分组年度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138317/

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