我是iOS新手。我正在创建一个应用程序,用户将根据他们指定的日期将客户端名称存储在数据库中。
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
有些客户每天都会重复,如何计算每个客户遇到我的次数,并将其每天保存到int。
例如
Monday
Nitin = 1
Vijay = 1
Akshay = 1
Ajit = 1
Sahil = 1
Ravi = 1
这应该每天上午12:00更新,如果我要求数据库在周二显示计数,它应该附带(周一计数+周二计数)
Tuesday
Nitin = 2
Vijay = 2
Akshay = 2
Ajit = 2
Sahil = 2
Ravi = 2
我应该如何实现它?
答案 0 :(得分:1)
假设您已使用以下表格对数据库进行了规范化:
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
...
然后您可以简单地计算每个客户的记录:
SELECT Client, COUNT(*)
FROM Appointments
WHERE DayID BETWEEN 0 AND 1 -- Monday and Tuesday
GROUP BY Client