带有两个select语句的PostgreSQLFunction

时间:2018-11-21 23:11:03

标签: postgresql function stored-procedures procedure

我正在尝试创建一个PostgreSQL函数,声明两个变量以在每个变量上返回不同查询的结果,该查询本身确实很简单,并且依赖具有不同条件的相同选择:

select count (*) from editions where year >= '2000'

select count (*) from editions where year < '2000'

表的结构也很简单,共有三行:

  1. 代码(数字)
  2. 版本(字符)
  3. 年份(整数)

如何创建此功能?

1 个答案:

答案 0 :(得分:0)

这是如此基础。.我想您可以在Google中找到许多教程来创建此<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" ></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" ></script> <div id="demo" class="carousel slide" data-ride="carousel"> <ul class="carousel-indicators"> <li data-target="#demo" data-slide-to="0" class="active"></li> <li data-target="#demo" data-slide-to="1"></li> <li data-target="#demo" data-slide-to="2"></li> </ul> <div class="carousel-inner"> <div class="carousel-item active"> <img src="https://dummyimage.com/600x400/000/fff&text=img1" alt="Clinic1" width="1100" height="500" /> <div class="carousel-caption "> <h3>Clinic 1</h3> </div> </div> <div class="carousel-item"> <img src="https://dummyimage.com/600x400/000/fff&text=img2" alt="Clinic2" width="1100" height="500" /> <div class="carousel-caption"> <h3>Clinic 2</h3> </div> </div> <div class="carousel-item"> <img src="https://dummyimage.com/600x400/000/fff&text=img2" alt="Clinic3" width="1100" height="500" /> <div class="carousel-caption container-fluid"> <h3>Clinic 3</h3> </div> </div> </div> <a class="carousel-control-prev" href="#demo" data-slide="prev"> <span class="carousel-control-prev-icon"></span> </a> <a class="carousel-control-next" href="#demo" data-slide="next"> <span class="carousel-control-next-icon"></span> </a> </div>。而且您的$('.carousel').carousel() 列为Function,所以请不要像{{ 1}}使用Year ..

函数totalRecords1()

Integer

函数totalRecords2()

String

还有Single Quote

CREATE OR REPLACE FUNCTION totalRecords1()
RETURNS integer AS $total1$
declare
    total1 integer;
BEGIN
   SELECT count(*) into total1 
   FROM your_table
   WHERE year >= 2000;
   RETURN total1;
END;
$total1$ LANGUAGE plpgsql;

您可以在DEMO

中看到