MySQL中的存储过程 [英] storeprocedure in mysql
本文介绍了MySQL中的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个表叫做citycontaing(id,name),另一个表区域containg(id,name,cityid_pk).有人可以帮我写storeprocedure或与此有关的任何链接吗?我是mysql数据库中的新手.我必须选择通过cityid将区域名称作为外键.
hi all,
i have one table called city containg(id,name) and another table areas containg(id,name,cityid_pk).can anybody please help me for writing storeprocedure or any link regarding this .i am new in mysql database.i have to select areaes name through cityid as foreign key.
CREATE PROCEDURE Sp_Select_area
(
`name` VARCHAR(300)
)
BEGIN
SELECT areas.`name`
FROM areas
JOIN cities
ON areas.cityid_fk=cities.id
ORDER BY areas.`name`
END;
谁能找出我在mysql中遇到的错误.
can anybody find out the error i have wriiten in mysql.
推荐答案
您可以在下面的链接中找到"MySQl Procedure".
http://dev.mysql.com/doc/refman/5.0/en/create- procedure.html
而此链接为"Joins".
http://dev.mysql.com/doc/refman/5.0/en/join.html
You may refer below link for "MySQl Procedure".
http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
And this link for "Joins".
http://dev.mysql.com/doc/refman/5.0/en/join.html
希望它能提供帮助
Hope it helpls
create procedure select_area()
begin
select
areas.Name
from (( areas a JOIN city c
ON a.cityid_pk = c.id) JOIN table3 on a.cityid_pk = table3.id and c.id=table3.id) ;
end |
您需要使用加入 [
You need to use a JOIN[^] statement.
The SQL statement would be:
SELECT t1.name AS area, t2.name AS city
FROM areas AS t1
JOIN city AS t2 ON t2.id = t1.cityid_pk;
这篇关于MySQL中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文