0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GoogleSpreadsheetのquery

Last updated at Posted at 2020-07-08

これはプログラムなのか、と言われると微妙なんだけど、GAS繋がり。

1.SpreadSheetのQuery関数について

集計

よくスプレットシートで、データを作成すると思います。

番号 名前 数量 開始日 終了日
1 神奈川 1 07/01 07/05
2 神奈川 2 07/06 07/10
3 千葉 4 07/01 07/05
4 千葉 3 07/06 07/12
5 埼玉 9 07/01 07/21

ここで、各県ごとの最初の開始日と最後の終了日が欲しい場合、以下のQuery関数で一発で出てくる
※B3が左上のセルとなっている

=query(B3:F7,"select C ,Sum(D),Min(E),Max(F) group by C")

これを入力したセルの上に

名前 数量 開始日 終了日
千葉 7 07/01 07/12
埼玉 9 07/01 07/21
神奈川 3 07/01 07/10

という結果が表示されます

検索

Filterでもできますが、こんな感じ

=query(B3:F7,"select C,D,E,F where C ='神奈川'")

同じくこれを入力したセルの上に

番号 名前 数量 開始日 終了日
1 神奈川 1 07/01 07/05
2 神奈川 2 07/06 07/10

となります

列名は大文字アルファベット、又はCol1、Col2というフォーマット。(Cは大文字必須)
SQL文法どこまで実装されてるか分かりませんが、結構使い出がありそう

こんな利用の仕方

第一引数の範囲を他のシートにすることもできます

=query(importrange(URL,RANGE),"select ...")

久しぶりに

Qita書こうと思ったら又マークダウン忘れてた

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?