读书人

求一条SQL句子:解决方案

发布时间: 2012-01-05 22:36:54 作者: rapoo

求一条SQL句子:
有这么一个表:
id name sex grade
1 aa 1 69
2 aa2 2 69
3 aa3 2 50
4 aa4 1 89
5 aa5 2 77
6 aa6 1 75
7 aa7 1 50

等等这样的数据,数据量特别大,现在想统计这样的数据: (sex 表示性别: 1,男;2 女)

列出男的分数(grade)>=60,女的(grade)>=50 的人员名单,看有好的建议没?

[解决办法]

SQL code
create Proc Proc_GetName    @BoyPoint int,    @GirlPoint intasbegin transaction    Declare @sql varchar(1024)    set @sql='elect name as 名单 where 1=1 '    if(@BoyPoint is not null)    begin        set @sql=@sql+'and sex=1 and grade>='+@BoyPoint    end    if(@GirlPoint is not null)    begin        set @sql=@sql='and sex=2 and grade>='+@GirlPoint    endexec(@sql)if @@error <>0begin    rollback transactionendelsebegin    commit transactionend 

读书人网 >asp.net

热点推荐