This topic is locked
[SOLVED]

create sql view

12/3/2022 2:14:33 PM
PHPRunner General questions
P
ppradhan@live.com author

This code works in the phpmyAdmin locally and in my webserver too. But while trying to create a custom sql view in phpr v10.8 latest build, It fails with below error.
Any help is highly appreciated.

img alt

Full mysql code is:

SELECT customer_id, c.customer_name, SUM(previous_dues.due_amt) AS TotDue, c.customer_type, c.delivery_type,

CASE
WHEN (previous_dues.d1 > 0 AND previous_dues.d2 > 0) || (previous_dues.d2 > 0 AND previous_dues.d3 > 0) || (previous_dues.d3 > 0 AND previous_dues.d1 > 0)
THEN 'HOT-DUE'

WHEN c.customer_type!= 1 AND (previous_dues.d1 > 0 || previous_dues.d2 > 0 || previous_dues.d3 > 0)
THEN 'HOT-DUE'

ELSE '-'
END AS STATUS,

previous_dues.d1, previous_dues.d2, previous_dues.d3, a.area_name, b.branch_name

FROM
(SELECT customer_id, due_amt, FIRST_VALUE(due_amt) over w AS d1, nth_value(due_amt, 2) over w AS d2, nth_value(due_amt, 3) over w AS d3
FROM customer_account ca
window w as (partition by customer_id order by date DESC range between unbounded preceding and UNBOUNDED FOLLOWING)) previous_dues

INNER JOIN customers c ON c.id = previous_dues.customer_id
INNER JOIN areas a ON a.area_id = c.area_id
INNER JOIN branches b ON b.id = a.branch_id

GROUP BY customer_id, previous_dues.d1, previous_dues.d2, previous_dues.d3
HAVING TotDue > 0

fhumanes 12/3/2022

Hello,

When the selects are very complex or have many selects, the analysis that Phprunner of these sentences does, sometimes they are lost (they present that phprunner builds new select using your sentence).

As I solve it is making these views in the database itself and use these views as if they were tables in Phprunner.

Cheers,
fernando

P
ppradhan@live.com author 12/4/2022

looks like the error is due to usage of lag function in mysql. Does phpr support such functions? because this works good with phpmyadmin locally and even in the live web server at the domain.
Please advice if there is something that can be changed so that the above query works.