Since each query will return a 1-row, 1-column result, you can just do a Cartesian join, i.e. ![]() Given examples of working queries, we can propose something like this, though there may be a more efficient way to achieve an equivalent result. Without knowing what you are attempting to achieve. Or, if more than one row is returned from one of the tables for the same site_id, that's going to produce "duplicate" rows, and the SUM will be inflated. If no rows are returned from one of the tables, then the query will return zero rows. there's potential there for producing a cross product (semi-Cartesian product) of those tables. CAST(SUM(PA.revenue))īut I don't think you want to join those tables. PC.CAST (SUM(PC.revenue) AS CHAR) revenueīut i have error in my syntax here.any idea how to do it?ĮRROR 1064 (42000): You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS CHAR) revenue,ĭon't qualify the function with a table alias. PB.CAST (SUM(PB.revenue) AS CHAR) revenue, PA.CAST (SUM(PA.revenue) AS CHAR) revenue, Problem is i want to get total revenue from all 3 tables, any idea how can i join them? 3- SELECT CAST(SUM(revenue) AS CHAR) revenue FROM PCĮach one will give me the revenue only from the queried table. MySQL also allows you to convert the values using the CAST() function, which you can check from here. You can try converting the value in every valid datatype using the CONVERT() function. We have studied and understood what CONVERT() function does, how it works, its parameters, and examples. 2- SELECT CAST(SUM(revenue) AS CHAR) revenue FROM PB This is all for MySQL CONVERT() function. WHERE site_id = 2 AND data_date BETWEEN '' AND '' ![]() ![]() 1- SELECT CAST(SUM(revenue) AS CHAR) revenue FROM PA
0 Comments
Leave a Reply. |