在增加列值方面需要帮助 [英] need help in incrementing a column value
本文介绍了在增加列值方面需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
Hi all
1 Manish 2012-09-24 16:46:12.037 1
3 nilam 2012-09-24 16:59:23.173 1
2 Dev 2012-09-24 17:04:22.907 1
1 Manish 2012-09-24 17:07:44.967 1
3 nilam 2012-09-24 17:09:38.950 1
我在上面的表格中..如您所见,同一个名字有2个条目..最后一个列是出席者.所以我想添加这些值.
例如为每个愿意加入的人添加
i m having the above table..as u can see the same name has 2 entries..the last colum is for attendence.so i want to add those values.
e.g. for each person it sould keep on add each time
推荐答案
请参阅以下解决方案.可能会对您有帮助.
Hi,
See the following solution. It might be help you.
IF (Select Count(ID) From Table_4 Where Name = 'Viprat') = 0
BEGIN
Insert Into Table_4 (Name, Attendance)
Values ('Viprat',1)
END
ELSE
BEGIN
Update Table_4
SET
Attendance = Attendance + 1
Where Name = 'Viprat'
END
您可以这样插入.
谢谢,
Viprat
You can insert like this.
Thanks,
Viprat
尝试一下
SELECT NAME,COUNT(NAME) FROM TABLE_NAME
GROUP BY NAME;
最好在count和group by语句中使用主键.
像这样
better to use primary key in the count and group by statement.
Like this
SELECT USER_ID,NAME,COUNT(PK_ID_OF_SEARCHING_TABLE) FROM TABLE_NAME
GROUP BY USER_ID;
这篇关于在增加列值方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文