用户定义的变量有问题

时间:2017-10-27 01:31:29

标签: mysql

我正在为我的SQL课程开发一个项目,我们正在做一个基于棋盘游戏Monopoly的项目。我必须使用"用户定义的变量"显示板上红色的位置。以下是我的表street_by_color_v的内容:

color_name  site_label       order_site

purple      Mediterranean Avenue    2
purple      Baltic Avenue   4
light blue  Oriental Avenue 7
light blue  Vermont Avenue  9
light blue  Connecticut Avenue  10
violet      St. Charles Place   12
violet      States Avenue   14
violet      Virginia Avenue 15
orange      St. James Place 17
orange      Tennessee Avenue    19
orange      New York Avenue 20
red         Kentucky Avenue 22
red         Indiana Avenue  24
red         Illinois Avenue 25
yellow      Atlantic Avenue 27
yellow      Ventor Avenue   28
yellow      Marvin Gardens  30
green       Pacific Avenue  32
green       North Carolina Avenue   33
green       Pennsylvania Avenue 35
royal blue  Park Place  38
royal blue  Boardwalk   40

这是我的代码:

SET @s_color:='red';

当我执行时,我运行代码:

SELECT site_label FROM street_by_color_v
WHERE color_name=@s_color;

并且它不起作用。

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT site_label FROM street_by_color_v
WHERE color_name='@s_color';

#example
SELECT site_label FROM street_by_color_v
WHERE color_name='royal blue';

SELECT site_label FROM street_by_color_v
WHERE color_name='orange';

谢谢.. :))