大家好我没什么问题,我有像那样的桌子
CREATE TABLE client(
regon VARCHAR NOT NULL,
title VARCHAR,
phone VARCHAR,
PRIMARY KEY(regon));
CREATE TABLE commodity(
id_com INT NOT NULL,
title VARCHAR,
PRIMARY KEY(id_com));
CREATE TABLE supply(
regon VARCHAR NOT NULL REFERENCES klient(regon),
id_supply INT NOT NULL,
id_com INT NOT NULLREFERENCES commodity(id_com),
quantity INT,
price DEC(5,2),
PRIMARY KEY(regon, id_supply, id_com));
我必须创建将返回所有耗材价值的函数(qantity * price) 我的功能如下:
CREATE OR REPLACE FUNCTION value1(out id int, out war double precision)as $$
select (quantity*price) as value from supply;
$$
language 'plpgsql';
但它只显示第一个商品的id为第一商品及其价值,但并非所有商品 也许 你知道怎么做吗? 感谢
答案 0 :(得分:0)
更改此select (quantity*price) as value from supply;
对此:
select sum(quantity*price) from supply
group by id_com
order by id_com
答案 1 :(得分:0)
我不得不做这样的查询:
select sum(quantity*price) from supply
group by id_com,quantity,price
order by id_com
并且它也向我显示id_com两次,比如我有两个商品,其中id为1,一个是400,第二个是30,我想我应该总结一下