如果条件在特定列中等于1,我想计算所有值。
我正在运行此查询:
$where_clause = '
aatt.sid = "'.$mybb->input['sid'].'"
AND att.att_month = "'.$mybb->input['att_month'].'"
AND att.att_year = "'.$mybb->input['att_year'].'"';
$query = $db->query("
SELECT SUM(aatt.present='1') AS total_present, SUM(aatt.absent='1') AS total_absent, aatt.sid, att.att_date, att.att_month, att.att_year, aatt.present, aatt.absent, aatt.leave_submitted
FROM ".TABLE_PREFIX."school_att att
LEFT JOIN ".TABLE_PREFIX."school_att_attendance aatt ON (aatt.att_month=att.att_month)
WHERE {$where_clause}");
但它计算表中的整行。 :/
请帮忙
这是我的school_att_attendance
表。如您所见present
,absent
列。我只想要present = 1
然后计算来自1s
的所有present
柱。 absent
列的内容相同。
更新: 这是表格的文字代码;
>
(`aaid`, `sid`, `present`, `absent`, `leave_submitted`, `att_date`, `att_month`, `att_year`) VALUES
(1, '2', '1', '0', '0', '4', '4', '2018'),
(2, '38', '0', '1', '0', '4', '4', '2018'),
(3, '36', '0', '1', '1', '4', '4', '2018'),
(4, '36', '1', '0', '0', '5', '4', '2018'),
(5, '2', '1', '0', '0', '5', '4', '2018'),
(6, '38', '0', '1', '0', '5', '4', '2018'),
(7, '38', '1', '0', '0', '6', '4', '2018'),
(8, '36', '1', '0', '0', '6', '4', '2018'),
(9, '2', '1', '0', '0', '6', '4', '2018'),
(10, '38', '1', '0', '0', '7', '4', '2018'),
(11, '36', '1', '0', '0', '7', '4', '2018'),
(12, '2', '0', '1', '0', '7', '4', '2018')
答案 0 :(得分:2)
如果你想要求和,你应该使用与ccorrect级别的聚合相关的分组ind这个案例我建议样本tt.att_date,att.att_month,att.att_year
import pandas as pd
data_csv = StringIO(data)
data_df = pd.read_csv(data_csv, sep = ".")