各位高手帮帮偶
我想作一个这样的东西
数据库如下
用户表
userID  userName  userPass
发送短信表
messageId messageName send  表结构大概是这样子
这个send就是userName我在程序里绑定了
而这个userName不一定是动态的客户想输注册什么就注册什么
而我要查询的是  发送短信表
根据send出现次数来统计
比如发送短信表send里有三个张三
我们就出现一个用户名    发短信次数
张三       3
但是这个名字我们不确定应为是用户注册的
可能不叫张三也可能叫李四
就是这个问题
查询的时候只要判断用户表里面的userName里的值
发送短信表里出现的次数记录下来在GridVilew里显示
谢谢各位了
帮帮偶

解决方案 »

  1.   

    LZ描述的好像是SQL问题。。
    select count(*) from 发送短信表 sendMessage where send =@name --@name为username
    而且只有一个数的话,用不着gridview了吧,显示出来就可以了
      

  2.   

    select send, count(send) from 发送短信表 group by send
      

  3.   


    create table #TB_UserName(userID int identity(1,1),userName nvarchar(20),userPass nvarchar(20))
    insert into #TB_UserName
    select 'Takako','123' union all
    select 'wu14245670','abc' union all
    select 'Kitty','ASD'
    gocreate table #TB_Send(messageID int identity(1,1),messageName nvarchar(4000),[send] nvarchar(20))
    insert into #TB_Send
    select 'Hello word','Takako' union all
    select 'Hello','wu14245670' union all
    select 'C#','Takako' union all
    select 'SQL','路人甲'
    goselect A.userName,count(userName) as sendCount 
    from #TB_UserName A inner join #TB_Send B 
    on A.userName=B.[send]
    group by A.userName
    godrop table #TB_UserName
    drop table #TB_Send
    /*
    (3 個資料列受到影響)(4 個資料列受到影響)
    userName             sendCount
    -------------------- -----------
    Takako               2
    wu14245670           1(2 個資料列受到影響)
    */
      

  4.   

    select [send] as 用户名,count(1) as 发短信次数 from  发送短信表 group by [send]