![](/img/trans.png)
[英]I want to add a search in my sql database, function to get the name by the id creates an error
[英]I want to add this function in sql in a Postgresql Database
我寫了這個功能:
create function check_same_price() returns integer as $result$
declare
result integer;
begin
set res = (select *
from (select count(distinct title), price_dvd_buy
from dvd_to_buy
group by price_dvd_buy) as dummy
where count>1);
if (res==none) then result=0;
else result=1;
end if;
end;
$result$ language plpgsql;
如果同一標題的價格相同,則該函數返回0,否則返回1。執行此檢查的原因是我希望同一部電影的價格相同; 我正在使用phppgadmin進行管理。 我收到此錯誤:
SQL error:
ERROR: error of sintax to or near "("
LINE 5: set res = (select *
怎么了,我不知道要解決。 謝謝!
create function check_same_price()
returns boolean as $$
begin
return exists(select count(distinct title)
from dvd_to_buy
group by price_dvd_buy
having count(distinct title) > 1)
end;
$$ language plpgsql;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.