我将维护我教堂的数据库,我在计算特定区域服务的现有家庭数量时遇到了困难,但是我能够计算区域的现有成员,如果一个家庭从我的教堂转移,那么如何更新家庭以获取每个区域的现有家庭,这里是 MWE,这里唯一 ID 是家庭号码,我想要“现有家庭”列条目,正如您在第一张图片中看到的,有一个“现有成员”列的条目,问题非常简单,但很难实现,我要填写每个 Areawise 列的现有家庭,上面显示的第一张图片是我的教堂的成员的数据,它将从 .csv 文件中读取,如您所见,唯一 ID 条目是每个家庭的 ID,在这个数据中,我总共有 6 栋房子,如您所见,“转移”列,N = 没有转移,Y = 是转移,如果一个家庭离开了我的教堂,那么剩下的现有家庭总数是 5,让我们看第一张图片家庭 ID 为 DBC0006 和 DBC0004 已从我的教堂,在这个家庭 ID DBC0006 中,我们共有 5 名成员,分别是 Raju 先生、Virendra Teron 先生、Klen 先生、Beauty 小姐和 Elvin 先生(即,他们属于同一个家庭 ID DBC0006),并且这个家庭属于“区域编号 2”的列,同样,对于 DBC0004,共有 2 名成员,分别是 Gilbert 先生和 Dinesh 先生,所以我的表格应该提供更新的列条目和更新的现有成员,如第 3 张图所示
\documentclass[12pt,a4paper,landscape]{report}
\usepackage[top=0.5cm,bottom=1.5cm]{geometry}
\usepackage[all]{tcolorbox}
\usepackage{setspace,filecontents}
\usepackage[english]{babel}
\usepackage{graphicx,booktabs,xstring,datatool,xintexpr,longtable,minted} %for including eps graphics
\renewcommand{\dtldisplaystarttab}{\toprule}
\renewcommand{\dtldisplayafterhead}{\midrule}
\renewcommand{\dtldisplayendtab}{\\\bottomrule}
\begin{filecontents*}{MemberSummary.csv}
Unique ID,Name,Gender,Baptised,Death,Transfer,Areawise
DBC0001,Mr. John,M,Y,N,N,Area No.1
DBC0002,Miss Elizabeth,F,Y,N,N,Area No.1
DBC0003,Mr. Thomas,M,N,N,N,Area No.2
,Miss Maya,F,N,Y,,Area No.2
DBC0004,Mr. Gilbert,M,Y,N,Y,Area No.3
,Mr. Dinesh,M,N,Y,,Area No.3
DBC0005,Miss Shanti,F,N,N,N,Area No.1
,Mr. Rajesh,M,Y,N,N,Area No.1
DBC0006,Mr. Raju,M,Y,N,Y,Area No.2
,Mr. Virendra Teron,M,Y,Y,,Area No.2
,Mr. Klen,M,Y,N,Y,Area No.2
,Miss Beauty,F,Y,Y,,Area No.2
,Mr. Elvin,M,Y,Y,,Area No.2
\end{filecontents*}
\renewcommand{\dtldisplaystarttab}{\toprule}
\renewcommand{\dtldisplayafterhead}{\midrule}
\renewcommand{\dtldisplayendtab}{\\\bottomrule}
\DTLloaddb{summary}{MemberSummary.csv}
\newcounter{A}
\newcounter{B}
\newcounter{C}
\newcounter{TotalA}
\newcounter{AH1}
\newcounter{AH2}
\newcounter{AH3}
\newcounter{TotalAH}
\begin{document}
\begin{longtable}{llccccl}
\toprule
Unique ID & Name & Gender & Baptised & Death & Transfer & Areawise\\
\midrule
\DTLforeach*{summary}{\id=Unique ID,\name=Name,\g=Gender,\b=Baptised,\d=Death,\tr=Transfer,\a=Areawise}{
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.1}{\stepcounter{A}}{}}{}}{}
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.2}{\stepcounter{B}}{}}{}}{}
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.3}{\stepcounter{C}}{}}{}}{}
\id & \name & \g & \b & \d & \tr & \a \\
}
\\\bottomrule
\end{longtable}
\setcounter{TotalA}{\numexpr\value{A}+\value{B}+\value{C}}
\bigskip
\begin{tabular}{lcc}
\toprule
Areawise &Existing Household & Existing Members\\
\midrule
Area No.1 & &\theA \\
Area No.2 & &\theB \\
Area No.3 & &\theC \\
\bottomrule
Total & &\theTotalA
\end{tabular}
\end{document}
更新了现有表条目
答案1
像这样吗?
\begin{filecontents*}{MemberSummary.csv}
Unique ID,Name,Gender,Baptised,Death,Transfer,Areawise
DBC0001,Mr. John,M,Y,N,N,Area No.1
DBC0002,Miss Elizabeth,F,Y,N,N,Area No.1
DBC0003,Mr. Thomas,M,N,N,N,Area No.2
,Miss Maya,F,N,Y,,Area No.2
DBC0004,Mr. Gilbert,M,Y,N,Y,Area No.3
,Mr. Dinesh,M,N,Y,,Area No.3
DBC0005,Miss Shanti,F,N,N,N,Area No.1
,Mr. Rajesh,M,Y,N,N,Area No.1
DBC0006,Mr. Raju,M,Y,N,Y,Area No.2
,Mr. Virendra Teron,M,Y,Y,,Area No.2
,Mr. Klen,M,Y,N,Y,Area No.2
,Miss Beauty,F,Y,Y,,Area No.2
,Mr. Elvin,M,Y,Y,,Area No.2
\end{filecontents*}
\documentclass[12pt,a4paper,landscape]{report}
\usepackage[top=0.5cm,bottom=1.5cm]{geometry}
\usepackage{setspace}
\usepackage{booktabs,xstring,datatool,longtable}
\renewcommand{\dtldisplaystarttab}{\toprule}
\renewcommand{\dtldisplayafterhead}{\midrule}
\renewcommand{\dtldisplayendtab}{\\\bottomrule}
\renewcommand{\dtldisplaystarttab}{\toprule}
\renewcommand{\dtldisplayafterhead}{\midrule}
\renewcommand{\dtldisplayendtab}{\\\bottomrule}
\DTLloaddb{summary}{MemberSummary.csv}
\newcounter{A}
\newcounter{B}
\newcounter{C}
\newcounter{TotalA}
\newcounter{AH}
\newcounter{BH}
\newcounter{CH}
\newcounter{TotalAH}
\begin{document}
\begin{longtable}{llccccl}
\toprule
Unique ID & Name & Gender & Baptised & Death & Transfer & Areawise\\
\midrule
\DTLforeach*{summary}{\id=Unique ID,\name=Name,\g=Gender,\b=Baptised,\d=Death,\tr=Transfer,\a=Areawise}{
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.1}{\stepcounter{A}}{}}{}}{}
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.2}{\stepcounter{B}}{}}{}}{}
\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.3}{\stepcounter{C}}{}}{}}{}
\IfStrEq{\id}{}{}{\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.1}{\stepcounter{AH}}{}}{}}{}}
\IfStrEq{\id}{}{}{\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.2}{\stepcounter{BH}}{}}{}}{}}
\IfStrEq{\id}{}{}{\IfStrEq{\d}{N}{\IfStrEq{\tr}{N}{\IfStrEq{\a}{Area No.3}{\stepcounter{CH}}{}}{}}{}}
\id & \name & \g & \b & \d & \tr & \a \\
}
\\\bottomrule
\end{longtable}
\setcounter{TotalA}{\numexpr\value{A}+\value{B}+\value{C}}
\setcounter{TotalAH}{\numexpr\value{AH}+\value{BH}+\value{CH}}
\bigskip
\begin{tabular}{lcc}
\toprule
Areawise &Existing Household & Existing Members\\
\midrule
Area No.1 & \theAH &\theA \\
Area No.2 & \theBH &\theB \\
Area No.3 & \theCH &\theC \\
\midrule
Total & \theTotalAH &\theTotalA\\
\bottomrule
\end{tabular}
\end{document}
输出: