Transpose SQL code into MATLAB

3 visualizaciones (últimos 30 días)
Cristian Martin
Cristian Martin el 15 de Jun. de 2022
Hi,
I have an SQL query that is ok in Workbench, the results are I expected:
SELECT * FROM prices.prices WHERE (Var5 <= 125 and Var5 >= 124 OR Var6 <= 125 and Var6 >= 124 OR Var7 <= 125 and Var7 >= 124) AND (Var8 <= 6 and Var8 >= 5 OR Product <= 6 and Product >= 5 OR Var10 <= 6 and Var10 >= 5);
In Matlab I want to do a query in data base, based on 4 variables 2 min and 2 max values that search in 6 different columns . For only 2 variables min and max value work perfectly but if I add the other two variables to extend the selection in other three columns it failed to show wanted results.
This is the half working:
sqlquery = ['SELECT * FROM prices.prices WHERE Var5 <= ',caseta2 ' and Var5 >= ',caseta1 ' OR Var6 <= ',caseta2 ' and Var6 >= ',caseta1 ' OR Var7 <= ',caseta2 ' and Var7 >= ',caseta1];
And full code:
sqlquery = ['SELECT * FROM prices.prices WHERE Var5 <= ',caseta2 ' and Var5 >= ',caseta1 ' OR Var6 <= ',caseta2 ' and Var6 >= ',caseta1 ' OR Var7 <= ',caseta2 ' and Var7 >= ',caseta1 ' AND Var8 <= ',caseta4 ' and Var8 >= ',caseta3 ' OR Product <= ',caseta4 ' and Product >= ',caseta3 ' OR Var10 <= ',caseta4 ' and Var10 >= ',caseta3 ];
selectie = fetch(conn,sqlquery);
In the Workbench I could used paranthesis and "AND" between criteria but in Matlab I don't know how to use it

Respuestas (0)

Productos


Versión

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by