SQL为每个不同的值创建列

时间:2015-06-24 17:15:44

标签: sql postgresql aggregate amazon-redshift

我有一个看起来像这样的表:

var arDrone = require('ar-drone');
var client  = arDrone.createClient();
// Flat trim.
client.ftrim();

我想得到这样的结果:

 date | title | count
------+-------+-------
04/20 |  foo  |  420
04/20 |  bar  |  194
04/21 |  foo  |  23
04/21 |  bar  |  100

如何在Redshift SQL中执行此操作?谢谢!

1 个答案:

答案 0 :(得分:2)

我认为最简单的方法是使用group by with group:

<div class="box">
  <div class="chip">Chip1</div>
  <div class="chip">Chip2</div>
  <div class="chip">Chip3</div>
  <div class="chip">Chip4</div>
  <input class="textbox" type="text">
</div>
<br>
<div class="box">
  <div class="chip">Chip1</div>
  <div class="chip">Chip2</div>
  <div class="chip">Chip3</div>
  <div class="chip">Chip4</div>
  <div class="chip">Chip5</div>
  <div class="chip">Chip6</div>
  <div class="chip">Chip7</div>
  <div class="chip">Chip8</div>
  <div class="chip">Chip9</div>
  <input class="textbox" type="text">
</div>