zoukankan      html  css  js  c++  java
  • Question[SQL]:Can you use a SQL statement to calculating it!

    Question:Can you use a SQL statement to calculating it!

    How can I print "10 to 20" for books that sell for between $10 and $20,"unknown" for books whose price is null, and "other" for all other prices?

    Answer:

        if OBJECT_ID('dbo.Table101301'is not null
            
    drop table dbo.Table101301
        
    create table dbo.Table101301
        (
            
    [bookid] int not null,
            
    [bookname] varchar(10),
            
    [price] varchar(10
        )
        
    insert into dbo.Table101301 values(1,'book1'1)
        
    insert into dbo.Table101301 values(2,'book2'5)
        
    insert into dbo.Table101301 values(3,'book3'8)
        
    insert into dbo.Table101301 values(4,'book4'10)
        
    insert into dbo.Table101301 values(5,'book5'12)
        
    insert into dbo.Table101301 values(6,'book6'null)
        
    insert into dbo.Table101301 values(7,'book7'20)
        
    insert into dbo.Table101301 values(8,'book8'21)
        
    insert into dbo.Table101301 values(9,'book9'null)
        
        
    select [bookid][bookname],
            
    [price] = (
                
    case 
                    
    when [price]  is null then 'unknown' 
                    
    when [price] between 10 and 20 then '10 to 20'
                    
    else [price]
                
    end 
            )
            
    from dbo.Table101301    
        
        
    drop table dbo.Table101301
  • 相关阅读:
    CentOS6.4 安装nmon
    CentOS6.4 访问域局网中Windows的共享
    将类似 12.56MB 36.89KB 转成 以K为单位的数字【备忘】
    ICE中间件相关
    HDFS介绍
    漫画描述HDFS工作原理
    离线安装Cloudera Manager 5和CDH5
    storm集群相关资料
    kafka相关资料
    jstatd
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760190.html
Copyright © 2011-2022 走看看