Transpose SQL code into MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!