Select 来自 table 的值,其中值以逗号分隔的字符串
Select values from table where value in comma delimited string
这是我的第一个 post...
我正忙着在 Access 2010 中编写一个软件。我的 SQL 还不错,但我在这里有点难过。
我有一个 table 具有以下布局
ID = AutoNumber,
Category = Text,
SubCategory = Text,
Grades = Text.
以及以下数据
ID Category SubCategory Grades
2 Behaviour Good RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
3 Behaviour Not so Good RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
4 Health Doctor Note RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
5 Social Peer Pressure
6 Academics General Academic Knowledge 1,2,3
7 Academics Additional Academic Knowledge 1,2,3
8 Gross Motor Skills Kicks a ball that is moving towards him or her.
9 Gross Motor Skills Hops and jumps while in motion R
10 Gross Motor Skills Skips RR
11 Gross Motor Skills Gallops RR
12 Gross Motor Skills Jumps forward 10 times RR
13 Gross Motor Skills Catches a small bounced ball RR
14 Gross Motor Skills Turns somersault RR
15 Gross Motor Skills Alternates feet walking up or down stairs RR`
我正在尝试创建一个查询,其中 select 例如
SELECT SubCategory from CATEGORY WHERE GRADES LIKE R
应该return
Good
Not so Good
Doctors Note
Peer Pressure
Hops jumps and Skips
显然,如果我需要 Grades RRR 或 1 或 2 或 5,它应该 select 根据需要
请任何人提供帮助。
谢谢
沃伦
您可以通过运算符 LIKE
这样做:
SELECT SubCategory
FROM CATEGORY
WHERE ',' + GRADES + ',' LIKE '*,R,*'
或者如果你想将查询值'R'
单独作为参数:
SELECT SubCategory
FROM CATEGORY
WHERE ',' + GRADES + ',' LIKE '*,' + 'R' + ',*'
这是我的第一个 post... 我正忙着在 Access 2010 中编写一个软件。我的 SQL 还不错,但我在这里有点难过。
我有一个 table 具有以下布局
ID = AutoNumber,
Category = Text,
SubCategory = Text,
Grades = Text.
以及以下数据
ID Category SubCategory Grades
2 Behaviour Good RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
3 Behaviour Not so Good RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
4 Health Doctor Note RRR,RR,R,1,2,3,4,5,6,7,8,9,10,11,12
5 Social Peer Pressure
6 Academics General Academic Knowledge 1,2,3
7 Academics Additional Academic Knowledge 1,2,3
8 Gross Motor Skills Kicks a ball that is moving towards him or her.
9 Gross Motor Skills Hops and jumps while in motion R
10 Gross Motor Skills Skips RR
11 Gross Motor Skills Gallops RR
12 Gross Motor Skills Jumps forward 10 times RR
13 Gross Motor Skills Catches a small bounced ball RR
14 Gross Motor Skills Turns somersault RR
15 Gross Motor Skills Alternates feet walking up or down stairs RR`
我正在尝试创建一个查询,其中 select 例如
SELECT SubCategory from CATEGORY WHERE GRADES LIKE R
应该return
Good
Not so Good
Doctors Note
Peer Pressure
Hops jumps and Skips
显然,如果我需要 Grades RRR 或 1 或 2 或 5,它应该 select 根据需要
请任何人提供帮助。 谢谢 沃伦
您可以通过运算符 LIKE
这样做:
SELECT SubCategory
FROM CATEGORY
WHERE ',' + GRADES + ',' LIKE '*,R,*'
或者如果你想将查询值'R'
单独作为参数:
SELECT SubCategory
FROM CATEGORY
WHERE ',' + GRADES + ',' LIKE '*,' + 'R' + ',*'