很难的SQL语句(50分)

  • 主题发起人 主题发起人 piaoyun1987
  • 开始时间 开始时间
P

piaoyun1987

Unregistered / Unconfirmed
GUEST, unregistred user!
有一张表:<br>&nbsp;ID &nbsp;服务态度 &nbsp; <br>&nbsp; 1 &nbsp; 很好 &nbsp; &nbsp; &nbsp;<br>&nbsp; 2 &nbsp; 一般 &nbsp; <br>&nbsp; 3 &nbsp; &nbsp;好 <br>&nbsp; 4 &nbsp; &nbsp;差<br>&nbsp; 5 &nbsp; &nbsp;好<br>&nbsp; 6 &nbsp; &nbsp;很好 &nbsp; &nbsp; &nbsp; &nbsp;<br><br>我想让这个表变成这样的形式:<br>&nbsp; ID &nbsp; 统计<br>&nbsp; &nbsp;1 &nbsp; &nbsp;2<br>&nbsp; &nbsp;2 &nbsp; &nbsp;2<br>&nbsp; &nbsp;3 &nbsp; &nbsp;1<br>&nbsp; &nbsp;4 &nbsp; &nbsp;1<br>其中 ID:1:代表很好的个数 &nbsp; 2:代表好的个数 &nbsp; 3:代表一般的个数 &nbsp; 4:代表差的个数
 
用group 对服务态度 分组不就行了吗?
 
请你说详细一点摆<br>写点语句?
 
select 服务态度 ,Count(服务态度) <br>from table<br>group by 服务态度;
 
select case when 服务态度='很好'then '1' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when 服务态度='好'then '2' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when 服务态度='一般'then '3' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when 服务态度='差'then '4' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp;as ID,Count(服务态度) <br>from table<br>group by ID
 
楼上那样写就成...
 
差不多就是这样子的.
 
同意楼上的,Group By ,Count就可以出结果!
 
后退
顶部