- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对 10 月份的列中的所有值求和,但我似乎有 unix 时间戳
我尝试了以下但值仍然为 0
<?php
echo $this->db->select('(SELECT SUM(amount_paid) FROM invoice WHERE MONTH ( `creation_timestamp` ) = 10) AS invoice');
$query = $this->db->get('invoice');
?>
..
CREATE TABLE `invoice`(
`invoice_id` int(11) NOT NULL AUTO_INCREMENT,
`student_id` int(11) NOT NULL,
`title` longtext COLLATE utf8_unicode_ci NOT NULL,
`description` longtext COLLATE utf8_unicode_ci NOT NULL,
`amount` int(11) NOT NULL,
`amount_paid` longtext COLLATE utf8_unicode_ci NOT NULL,
`due` longtext COLLATE utf8_unicode_ci NOT NULL,
`creation_timestamp` int(11) NOT NULL,
`payment_timestamp` longtext COLLATE utf8_unicode_ci NOT NULL,
`payment_method` longtext COLLATE utf8_unicode_ci NOT NULL,
`payment_details` longtext COLLATE utf8_unicode_ci NOT NULL,
`status` longtext COLLATE utf8_unicode_ci NOT NULL COMMENT 'paid or unpaid',
PRIMARY KEY (`invoice_id`)
) ENGINE=MyISAM AUTO_INCREMENT=73 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
最佳答案
试一试,因为我们正在寻找 2015 年 10 月的总和(我认为)
SELECT UNIX_TIMESTAMP('2015-10-01'); -- '1443672000'
SELECT UNIX_TIMESTAMP('2015-10-31 23:59:59'); -- 1446350399
SELECT UNIX_TIMESTAMP('2015-11-01'); -- '1446350400'
注意上面的值
drop table invoice2;
create table invoice2
( id int auto_increment primary key,
amount decimal(12,2) not null,
ts int(11) not null -- from unix timestamp
);
-- truncate table invoice2;
insert invoice2(amount,ts) values
(10,unix_timestamp('2015-10-01')),
(10,unix_timestamp('2015-10-01')),
(3310,unix_timestamp('2015-11-01')),
(3310,unix_timestamp('2015-11-01')),
(44410,unix_timestamp('2016-01-01')),
(5510,unix_timestamp('2016-02-01')),
(6610,unix_timestamp('2016-02-01'));
所以您想要 2015 年 10 月金额的以下 flavor 的东西:
select sum(amount) as theSum
from invoice2
where month(from_unixtime(ts))=10
and year(from_unixtime(ts))=2015;
+--------+
| theSum |
+--------+
| 20.00 |
+--------+
感兴趣的函数是get_sum()
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class department_model extends CI_Model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//read the department list from db
function get_department_list()
{
$sql = 'select var_dept_name, var_emp_name from tbl_dept, tbl_emp where tbl_dept.int_hod = tbl_emp.int_id';
$query = $this->db->query($sql);
$result = $query->result();
return $result;
}
// get the sum of amount based on parameters month and year passed
function get_sum($month,$year)
{ $myQuery="select sum(amount) as theSum from invoice2 where month(from_unixtime(ts))=$month
and year(from_unixtime(ts))=$year";
$query = $this->db->query($myQuery);
$result = $query->result();
return $result;
}
关于php - 根据带有 unix 时间戳的月份和年份选择总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33966476/
我正在完成一项让我难堪好几天的学校作业。任务是使用 View (VAvailableGolfers) 将与从组合框中选择的给定事件/年份无关的高尔夫球手填充到列表框中。以下是表中的数据: 那么,表单上
给定一年和那年的某一天,我如何获得完整的日期?例如:60/2014 = 2014 年 3 月 1 日 和 61/2016 = 2016 年 3 月 1 日 注释:-年和日可以作为单独的参数传递。 -结
我正在使用 ExtJS 3,当我想为日期选择器选择日期时,我只能设置日期和月份(通过左/右箭头)。月/年面板会放下来,但很快就会消失,因此无法选择它。这是最能描述该行为的桌面记录:http://fli
我正在尝试获取用于在 div 中显示当前月份和年份的 jquery 或 java 脚本代码,但目前还不能。我的意思是我想以这种格式显示当前的月份和年份:October 2012 这样每个月我都不需要编
我有这段代码可以从数据库中获取一个字段: $end_date=$row1['end_date']; 如果我打印它,它会给我这样的信息:25-09-2012我需要的是获取月份值、年份和日期。类似于: $
我有两个格式如下的数据集: df1 #> Artist Album Year #> 1 Beatles Sgt. Pepper's 1967 #>
我使用 jQuery 验证插件和 maskedInput 插件对输入进行了自定义日期和时间验证。 有没有办法在自定义验证中进行验证以防止输入大于当前年份的年份? 我的代码: $("#date").ma
我在 xml 解析方面没有经验,所以也许我写的一些东西对某些人来说看起来很愚蠢,也许我的一些术语不太正确。请原谅。 我开发了一个Android应用程序,它需要解析来自YR.no的天气数据。 。该组织提
我需要当前年份,月份和日期为3个不同的变量。下面的代码给出了日期时间 val now = Calendar.getInstance().getTime() 2016年9月29日星期四18:27:38
在模态对话框中使用日期选择器,请不要在 Firefox 19.0.2 中使用更改月/年下拉列表,请参阅: http://jsfiddle.net/469zV/2/ HTML
我希望日期输入在年份有 4 位数字后停止输入。我尝试使用 HTML 中的 min 和 max 组件,但它仍然允许您键入删除第一个数字。参见示例 1。 请参阅示例 2 以了解可以输入超过 4 位数字的年
因此不同是基于唯一的月/年,而不仅仅是一个不同的月份(所以我希望 2011 年 1 月和 2012 年 1 月是不同的) // Test set of data List Compl
在 Programming in the Key of C# 中,作者给出了一个示例(附源代码),说明如何将日期(年、月、日 -- 数字)打包为 32 位整数。在示例中,作者将信息打包如下: int
这里我有一个任务,如果我写这样的代码,年份应该像 1947 年到 2016 年一样绑定(bind)在 DropdownList 中 1947 2016 拍了一整天 最佳答案 例如,
显然,我的 SQL 不是最好的,但我想做的是通过查找条目中的最大年份和月份来获取数据库中的最新日期。现在我有: select max(Month), max(Year) from posts wher
我试图弄清楚是否有任何 ID 发生在任何早年(即 dfo 中的 Duplicate 列)。如果是这样,我想将该行标记为重复行并包括 ID 首次出现的年份(即 Year_Duplicate)。 我确实有
我已经从 df 中提取了列列表,这些列是字符串类型,如下所示:1999-1(如 1999 年第一个月)。 我想删除 2000 年之前的所有列,因此我提取了列列表并使用列表理解来检查字符串的第一个字符是
日期时间是什么时候?我的 DateTimePicker 控件的源更改为 null,我想选择另一个日期,日历下拉列表默认为最后选择的月份和年份。 我正在为 DOB 使用 DateTimePicker,因
我正在获取系统当前日期并尝试在 TextView 中显示它。 尝试下面的代码后 private OnClickListener listener1 = new OnClickListener() {
我想使用 knockoutJS 库验证年份。我面临的问题是,当用户输入错误的年份时,不会对年份进行验证。以下是年份错误的情况。 (01/01/12 becomes 01/01/0012) (01/0
我是一名优秀的程序员,十分优秀!