我有一个像这样的SQL查询:
string PendingMsgsQuery = "select FROM_CLIENT,CHAT_MSG from chat where TO_CLIENT=" + clientID + " and CHAT_STATUS='p' ";
并且图像中的DataTable希望它通过此查询从结果返回得到它的值'FROM_CLient'不是静态的,它可能会根据'TO_CLIENT'值而变化
我的问题是: 我想为该客户端返回From_CLient的ID和CHAT_MSG的计数我该怎么办呢?有什么特别的解决方案吗?
答案 0 :(得分:0)
您可以进行group by
查询,按FROM_CLIENT
分组
string PendingMsgsQuery = "select FROM_CLIENT, count(0) as QUANTITY from chat where TO_CLIENT=" + clientID + " and CHAT_STATUS='p' group by FROM_CLIENT ";