-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.sql
184 lines (137 loc) · 2.76 KB
/
words.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
--use standb
create table word5
(
word char(5) not null
)
create table word6
(
word char(6) not null
)
select top 10 * from [dbo].[Collins Scrabble Words (2019)]
go
drop table words
go
create table words(
word varchar(15),
[length] int
)
go
CREATE NONCLUSTERED INDEX ix_len
ON dbo.words([length])
go
insert words(word, length)
select column1, len(column1) from [dbo].[Collins Scrabble Words (2019)]
where len(column1) <= 15
go
select top 10 word
from words
where [length]=5
and substring(word,1,1) = 'A'
insert word5
select [column1] from [dbo].[Collins Scrabble Words (2019)]
where len([column1]) = 5
insert word6
select [column1] from [dbo].[Collins Scrabble Words (2019)]
where len([column1]) = 6
create view vwWord5
as
select
word,
substring(word,1,1) [p1],
substring(word,2,1) [p2],
substring(word,3,1) [p3],
substring(word,4,1) [p4],
substring(word,5,1) [p5],
CHARINDEX('A',word) [A],
CHARINDEX('B',word) [B],
CHARINDEX('C',word) [C],
CHARINDEX('D',word) [D],
CHARINDEX('E',word) [E],
CHARINDEX('F',word) [F],
CHARINDEX('G',word) [G],
CHARINDEX('H',word) [H],
CHARINDEX('I',word) [I],
CHARINDEX('J',word) [J],
CHARINDEX('K',word) [K],
CHARINDEX('L',word) [L],
CHARINDEX('M',word) [M],
CHARINDEX('N',word) [N],
CHARINDEX('O',word) [O],
CHARINDEX('P',word) [P],
CHARINDEX('Q',word) [Q],
CHARINDEX('R',word) [R],
CHARINDEX('S',word) [S],
CHARINDEX('T',word) [T],
CHARINDEX('U',word) [U],
CHARINDEX('V',word) [V],
CHARINDEX('W',word) [W],
CHARINDEX('X',word) [X],
CHARINDEX('Y',word) [Y],
CHARINDEX('Z',word) [Z]
from word5
go
create view vwWord6
as
select
word,
substring(word,1,1) [p1],
substring(word,2,1) [p2],
substring(word,3,1) [p3],
substring(word,4,1) [p4],
substring(word,5,1) [p5],
substring(word,6,1) [p6],
CHARINDEX('A',word) [A],
CHARINDEX('B',word) [B],
CHARINDEX('C',word) [C],
CHARINDEX('D',word) [D],
CHARINDEX('E',word) [E],
CHARINDEX('F',word) [F],
CHARINDEX('G',word) [G],
CHARINDEX('H',word) [H],
CHARINDEX('I',word) [I],
CHARINDEX('J',word) [J],
CHARINDEX('K',word) [K],
CHARINDEX('L',word) [L],
CHARINDEX('M',word) [M],
CHARINDEX('N',word) [N],
CHARINDEX('O',word) [O],
CHARINDEX('P',word) [P],
CHARINDEX('Q',word) [Q],
CHARINDEX('R',word) [R],
CHARINDEX('S',word) [S],
CHARINDEX('T',word) [T],
CHARINDEX('U',word) [U],
CHARINDEX('V',word) [V],
CHARINDEX('W',word) [W],
CHARINDEX('X',word) [X],
CHARINDEX('Y',word) [Y],
CHARINDEX('Z',word) [Z]
from word6
go
-- 5 letter
select word
from vwWord5
where 1=1
and p2 = 'O'
and p5 = 'E'
--and S in (5)
and G in (1,3)
--and Y in (5)
and 0= S+T+A+M+F+R
/*
?p1=D&p5=S&A=3&R=2,4&0=TEM
*/
select *
from vwWord5
where
S in (1,2)
-- 6 letter
select word
from vwWord6
where
S in (3,4)
and E in (1,5,6)
and A in (2,5)
and T = 0
and M = 0
and K = 0