[英]count entries in database
I am new to sqlite for iOS. 我是iOS的sqlite的新手。 I am making an app in which user will store the client names in the database according to the day they're appointed. 我正在制作一个应用程序,用户将根据任命的日期将客户端名称存储在数据库中。
id Day Client1 Client2 Client3 Client4 Client5 Client6
0 Monday Nitin Vijay Akshay Ajit Sahil Ravi
1 Tuesday Ravi Akshay Nitin Sahil Vijay Ajit
2 Wednesday Vijay Nitin Vijay Akshay Ravi Ajit
3 Thursday Akshay Ajit Nitin Ravi Sahil Vijay
4 Friday Nitin Nitin Akshay Sahil Ravi Vijay
Some clients will be repeated daily, how to count number of times each client has met me and save it to int every day. 每天都会重复一些客户,如何计算每个客户遇到我的次数并将其每天保存到int。
eg. 例如。
Monday
Nitin = 1
Vijay = 1
Akshay = 1
Ajit = 1
Sahil = 1
Ravi = 1
This should be updated daily at 12:00AM and if I request database to show the count on Tuesday, it should come with (Count on Monday + Count on Tuesday) 这应该在每天的12:00 AM进行更新,如果我请求数据库显示星期二的计数,它应该随附于(星期一计数+星期二计数)
Tuesday
Nitin = 2
Vijay = 2
Akshay = 2
Ajit = 2
Sahil = 2
Ravi = 2
How should I achieve it? 我应该如何实现?
Assuming that you have normalized your database, with tables like these: 假设您已经使用以下表格规范化了数据库:
Days: id Day
0 Monday
1 Tuesday
2 Wednesday
...
Appointments: DayID Client
0 Nitin
0 Vijay
0 Akshay
0 Ajit
0 Sahil
0 Ravi
1 Ravi
1 Akshay
1 Nitin
...
then you can simply count the records for each client: 那么您可以简单地计算每个客户的记录:
SELECT Client, COUNT(*)
FROM Appointments
WHERE DayID BETWEEN 0 AND 1 -- Monday and Tuesday
GROUP BY Client
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.