简体   繁体   中英

How to write a stored procedure in mysql for multiple parameters in select statement?

This is the first time I am writing a stored procedure. Here is my stored procedure

CREATE DEFINER=`test`@`%` PROCEDURE `List`(OUT id INT, OUT SCORE INT)
BEGIN
select (Listing.Viewcount * 0.4) + count(Bookmarks.ListingId * 0.6) As Score INTO SCORE, distinct(Listing.ListingId) INTO id
from Listing,Bookmarks
where Listing.ListingId = Bookmarks.ListingId
group by Listing.ListingId
order by Score desc
Limit 10;
END

It is giving an error on select statement saying "Syntax error: unexpected (distinct) distinct". I am not able to figure out why is this wrong ? Help is highly appreciated! :) Thanks.

CREATE DEFINER=`test`@`%` PROCEDURE `List`(OUT id INT, OUT SCORE INT)
BEGIN
select (Listing.Viewcount * 0.4) + count(Bookmarks.ListingId * 0.6),distinct(Listing.ListingId)
       INTO SCORE, id
from Listing,Bookmarks
where Listing.ListingId = Bookmarks.ListingId
group by Listing.ListingId
order by Score desc
Limit 1;
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM