ios - 统计数据库中的条目
<p><p>我是 iOS 版 sqlite 的新手。我正在制作一个应用程序,用户将根据指定日期将客户名称存储在数据库中。</p>
<pre><code>id Day Client1 Client2 Client3 Client4 Client5 Client6
0Monday Nitin Vijay Akshay Ajit Sahil Ravi
1Tuesday Ravi Akshay Nitin Sahil Vijay Ajit
2Wednesday Vijay Nitin Vijay Akshay Ravi Ajit
3Thursday Akshay Ajit Nitin Ravi Sahil Vijay
4Friday Nitin Nitin Akshay Sahil Ravi Vijay
</code></pre>
<p>有些客户每天都会重复,如何统计每个客户每天遇到我的次数并保存到int。</p>
<p>例如。</p>
<pre><code>Monday
Nitin = 1
Vijay = 1
Akshay = 1
Ajit = 1
Sahil = 1
Ravi = 1
</code></pre>
<p>这应该在每天上午 12:00 更新,如果我请求数据库显示周二的计数,它应该附带(周一计数 + 周二计数)</p>
<pre><code>Tuesday
Nitin = 2
Vijay = 2
Akshay = 2
Ajit = 2
Sahil = 2
Ravi = 2
</code></pre>
<p>我应该如何实现它?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>假设您已经对数据库进行了规范化,使用如下表:</p>
<pre><code>Days:idDay
0 Monday
1 Tuesday
2 Wednesday
...
Appointments:DayIDClient
0 Nitin
0 Vijay
0 Akshay
0 Ajit
0 Sahil
0 Ravi
1 Ravi
1 Akshay
1 Nitin
...
</code></pre>
<p>那么您可以简单地计算每个客户的记录:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT Client, COUNT(*)
FROM Appointments
WHERE DayID BETWEEN 0 AND 1-- Monday and Tuesday
GROUP BY Client
</code></pre></p>
<p style="font-size: 20px;">关于ios - 统计数据库中的条目,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19533702/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19533702/
</a>
</p>
页:
[1]