Help in calc element from sql query

aflores

New Member
Hi. I have a sql statement which works as I need in phpMyAdmin but I have no idea how to code it in a calc element. I'm newbie in Fabrik, any suggestion is greatly appreciated.

-- Delete existing temporary table and create a new one from a query:
DROP TABLE IF EXISTS tmp1;
CREATE TABLE IF NOT EXISTS tmp1
SELECT concepto,SUM(importe) AS suma
FROM directo
GROUP BY directo.concepto;

-- Update data from the temporary table to an existing one:
UPDATE conceptos, tmp1
SET conceptos.insumos = tmp1.suma
WHERE conceptos.id = tmp1.concepto;
 
That really doesn't look like the kind of thing you'd want to be doing in a calc element.

What are you actually trying to achieve?

-- hugh
 
Thanks for your fast reply Hugh. You're right this looks messy. Let me try to explain.

What I want is the sum of the element 'importe' from the list 'directo' grouped by the key 'concepto' and then update the element 'insumos' from the list 'conceptos' with this results to their corresponding IDs, but I don't know if it is possible to do in a calc element and how.
 
Anything complex like that, always best to do in a form PHP plugin.

I think you could do that in a single query, no need to use a temporary table, although I can't really help with that in Community support. You could probably get some help with the basic query to use over on stackoverflow.com. Once you have a query that works (test it in phpMyAdmin), we could give you some hints on how to then run it in a submission plugin.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top