Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ambiguous Groups #sqlap
Search
grimrose
February 05, 2014
Programming
0
860
Ambiguous Groups #sqlap
SQLアンチパターン読書会 「アンビギュアスグループ」
grimrose
February 05, 2014
Tweet
Share
More Decks by grimrose
See All by grimrose
だいたい10分くらいで 知った気になれる Vert.x 3.0 #渋谷Java / Shibuya.java #11
grimrose
0
1.8k
Syobochim should read book of modeling #syoboben
grimrose
0
1.7k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
5.9k
I wanna tell you about "Groovy Template"
grimrose
3
5.3k
Groovy Shell with Gradle
grimrose
0
5.1k
Shibuya.Java #07
grimrose
0
810
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
250
Shibuya.Java #04
grimrose
1
600
I made out Gradle plug-in
grimrose
0
900
Other Decks in Programming
See All in Programming
なぜselectはselectではないのか
taiyow
2
310
List とは何か? / PHPerKaigi 2025
meihei3
0
570
DomainException と Result 型で作る型安全なエラーハンドリング
karszawa
0
760
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
2
1.1k
PHPのガベージコレクションを深掘りしよう
rinchoku
0
250
AIエージェントを活用したアプリ開発手法の模索
kumamotone
1
760
Go1.24で testing.B.Loopが爆誕
kuro_kurorrr
0
170
AHC 044 混合整数計画ソルバー解法
kiri8128
0
300
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
360
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
130
Return of the Full-Stack Developer
simas
PRO
1
320
MCP世界への招待: AIエンジニアが創る次世代エージェント連携の世界
gunta
3
740
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
The Invisible Side of Design
smashingmag
299
50k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
320
Gamification - CAS2011
davidbonilla
81
5.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
28
1.6k
KATA
mclloyd
29
14k
Designing Experiences People Love
moore
141
23k
Why Our Code Smells
bkeepers
PRO
336
57k
How STYLIGHT went responsive
nonsquared
99
5.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
A better future with KSS
kneath
238
17k
Transcript
SQLアンチパターン読書会 14章 「アンビギュアスグループ」 2014/02/06 @grimrose
目的 グループ内で最大値を持つ行
アンチパターン 非グループ化列を参照する
単一値の原則 Single-Value Rule
アンチパターンの見つけ方 _人人人人人人人人人人_ > エラーメッセージ <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ ※SQLiteとMySQLを除く
アンチパターンを用いてもよい場合 MySQLとSQLiteの場合 関係従属性を持つ列のみに クエリを実行するように注意
解決策 曖昧でない列を使用する
関数従属性のある列のみ クエリから曖昧な列を排除
相関サブクエリ • 読みやすい • コードの記述も簡単 • パフォーマンスに注意
導出テーブル • 相関サブクエリよりパフォーマ ンスが高い • テンポラリテーブル
JOIN • 大量のデータに対するパフォーマンス が重要な場合 • パフォーマンスの測定してね
他の列に対しても集約関数 単一値の原則
グループ毎に全ての値を連結 • GROUP_CONCAT関数 ◦ MySQL, SQLite • PostgreSQLの場合 ◦ ARRAY_TO_STRING(ARRAY_AGG(any),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う