我在postgres表中有一个金额,我可以通过查询select sum (price) from xyz
我想在不同的级别转换这个值,就像我将它转换为
Price > 2000
1000 - 2000
500 - 1000
Price < 500
我想在网站的过滤器中显示它...我正在使用(postgres,codeiginiter,javascript,jquery)可以使用任何语言帮助我创建该格式
答案 0 :(得分:0)
finaly create thanx to all
select t1.row_number,t1.left,t2.right from
(SELECT row_number() over(),f2.* from(
SELECT generate_series(max(purchase_price::integer) , min(purchase_price::integer),-((max(purchase_price::integer))/5)) AS left FROM tbl_products) f2) t1
join
(SELECT row_number() over(),f.* from(
(SELECT generate_series(max(purchase_price::integer) , min(purchase_price::integer),-((max(purchase_price::integer))/5)) AS right FROM tbl_products offset 1)
union all
(select '0' as right)) f)t2
on t1.row_number =t2.row_number
答案 1 :(得分:0)
我有这个查询
<form [FormGroup]="form" (ngSubmit)="onSubmit(form.value)"> <input type="text" placeholder="firstname" name="firstname" formControlName="firstname" /> <br> <input type="text" placeholder="lastname" name="lastname" formControlName="lastname" /> <br> <select name="languages" formControlName="languages"> <option value="C++">C++</option> <option value="Java">Java</option> <option value="Angular">Angular</option> </select> <br><br> <input type="submit" value="submit" /> </form>
....左右列显示相同的值...我只想要右列开始第二个值,最后一行显示0
你为什么要用SQL做这件事?
像
这样的东西
SELECT generate_series(10000 , 2001,-((10000)/5)) AS left, generate_series(10000 , 2001,-((10000)/5)) AS right
&#13;
var arr = [];
for(var i=10000; i >= 2001; )
arr.push([i, i -= 10000/5]);
console.log(arr);
&#13;
.as-console-wrapper{top:0;max-height:100%!important}
与... and last row show 0
的结束值相矛盾。您的函数调用将生成系列2001
,甚至不存在2000。那么一个人呢? 0或2001?
或者,如果以前的代码看起来像#34; hacky&#34;对你:
[10000, 8000, 6000, 4000]