SQL 小白的白痴问题

我是一个SQL小白,零基础,但是因为工作需要,需要立即使用

现在的水平只限于照猫画虎,但是因为基础为零,所以很多基础问题都不明白

特此来这里希望各位帮忙解惑

 

我需要这样一个数据的呈现

城市10分钟以下等候人数10-15分钟等候人数
北京10人10人
上海15人15人
广州20人20人

 我写的代码是:

SELECT tt.area_city,count(customerid)
,sum(case when (t.queue_time/1000)<600 then 1 else 0 end) as [0-10]
,sum(case when (queue_time/1000)>=600 and (queue_time/1000)<900 then 1 else 0 end) as [10-15]
,sum(case when (queue_time/1000)>=900 and (queue_time/1000)<1800 then 1 else 0 end) as [20-30]
sum(case when (queue_time/1000)<=1800 then 1 else 0 end) as [30+]

但是会报错,找了公司技术人员,修改后为:

SELECT tt.area_city,count(customerid) as customnumber
,sum(case when cast(queue_time as int)/1000 < 600 then 1 else 0 end) as shiyixia
,sum(case when cast(queue_time as int)/1000>=600 and cast(queue_time as int)/1000<900 then 1 else 0 end) as shidaoshiwu
,sum(case when cast(queue_time as int)/1000>=900 and cast(queue_time as int)/1000<1800 then 1 else 0 end) as shiwudaosanshi
,sum(case when cast(queue_time as int)/1000<=1800 then 1 else 0 end) as sanshiyishang

那么我的疑问是:

1.queue_time为什么要别名

2.为什么要加CAST进行函数转换

3.为什么不能用英文以外的表述来命名

问题可能很白痴,但是真心没有基础,就想知道一下,下次可以知道怎么用,摆脱找马画虎但是四不像的困扰

 

谢谢各位

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值