I have a requirement to calculate a number value by using the results of two sql queries. I know this is possible in python etc but if I want to use the results of sql queries in say, apache superset, how can I achieve this?
For ex:
query1: select * from consumer;
result: 190 rows
query2: select * from producer;
result: 230 rows
value I need, called output : 190/230.
Is this possible using sub queries? How can I extract the output alone?
Related
I am trying to select the maximum value of the last 6 digits in a list of strings
This is for creating an Inbox Query in Infor EAM
OBJ_CODE is the column and R5OBJECTS is the table. I have tried the following code but the number returned is 0.
SELECT MAX(RIGHT(OBJ_CODE,6)) FROM R5OBJECTS
My list looks like this
AAAA100000
AAAA100001
AAAA100002
AAAA100003
AAAA100004
AAAA100005
...
AAAA100999
...
BBBB100006
BBBB100007
BBBB100008
BBBB100009
BBBB100010
So the expected output would be 100999
It seems this table R5OBJECTS is too big, and your sql query performance didn't pass the base configuration parameter.
If using Inbox -> Set your INBXSCOR to 50 and try your query again.
If using KPI -> Set your KPISCOR to 50
SQL Statement
Enter the SQL statement to calculate the number of applicable records
for the inbox entry. The system automatically populates SQL Statement
Text. Note: SQL Statement cannot exceed the performance score limit
defined in the INBXSCOR installation parameter.
https://docs.infor.com/eam/11.3.2/en-us/eamolh/cdh1498150395934.html
Although this code works perfectly form me in SQL Server 2016, I add additional function to convert string to int to be sure:
SELECT MAX(CONVERT(INT,RIGHT(OBJ_CODE,6))) FROM R5OBJECTS
I'm looking for SQL query that will give me a simple percentage value based upon the number of occurrences of a value in a table with a single data column.
Example:
Table has single column of data, which has a header and 10 data rows:
COLUMN_HEADER
XYZ://abc123xyz456-0
XYZ://abc123xyz456-1
XYZ://abc123xyz456-2
XYZ://abc123xyz456-3
ABC://abc123xyz456-4
XYZ://abc123xyz456-5
XYZ://abc123xyz456-6
ABC://abc123xyz456-7
XYZ://abc123xyz456-8
XYZ://abc123xyz456-9
I'm looking for the query to look for all data that does not start with XYZ://*
and give that as a % of the row count.
In the above example, there are two rows that start with ABC:// and eight that start XYZ:// therefore the result should be:
80.00%
(so 8 out of 10 rows do not start with XYZ://)
As you can tell by now I'm a noob in SQL.
MS SQL 2014
Thanks in advance.
You can do this with conditional aggregation:
select avg(case when COLUMN_HEADER like 'XYZ://%' then 1.0 else 0 end) as xyz_ratio
Your logic and examples are backwards. 80% of the rows have values that do start with "XYZ://". Use like or not like as appropriate.
I would like to make a BAPI call from Java to the BAPI "BAPI_MDDATASET_CREATE_OBJECT".
Therefore I want to use the following MDX Query:
SELECT
[0DISTR_CHAN].Members ON COLUMNS,
[0MATERIAL].Members ON ROWS
FROM [$/PKG/AB_C01]
Because the Parameter "COMMAND_TEXT" is to short I made 4 entries like this:
Now I run the BAPI and get a DATASETID in return. I use this id with the next BAPI "BAPI_MDDATASET_CHECK_SYNTAX"
But now I get an exception:
English Version:
Why is this so?
This MDX query seems to be OK, because in transcation "MDXTEST" this query is working.
Any suggestions?
I had the same problem only with c# and sap connector.
I solved it. Need to use all commands in one context:
RfcSessionManager.BeginContext(destination);
Create_Object();
CheckSyntax();
etc.
RfcSessionManager.EndContext(this.destination);
The following will return a large table that is n * m where n are the number of columns and m is the number of rows:
SELECT
[0DISTR_CHAN].Members ON COLUMNS,
[0MATERIAL].Members ON ROWS
FROM [$/PKG/AB_C01]
n = number of members in this dimension [0DISTR_CHAN] + 1
m = number of members in this dimension [0MATERIAL]
This is not an answer but maybe will help to discover if the mdx is the problem. If you simplify the above to just a single member on rows, and a single member on columns do you still get an error?
SELECT
{[0DISTR_CHAN].[0DISTR_CHAN].[someMemberY]} ON COLUMNS,
{[0MATERIAL].[0MATERIAL].[someMemberX]} ON ROWS
FROM [$/PKG/AB_C01];
I've a query:
QUERY1{statements...}
INTERSECT
QUERY2{statements...}
I need to evaluate these 2 queries according to giving database data, my question is:
do I have to evaluate each query separately and then combine the 2 results together? i.g: cost(Query1) + cost(Query2) = Total query's cost ? .. or there is another way to solve this?
Yes, you have to add the 2 queries' cost.
In Toad Oracle you can evaluate the global intersect query:
what am I doing wrong with my sql query? It always return an empty rows even if there is a value exist.
Here is my query:
SELECT *
FROM users
WHERE user_theme_id IN ( 9735, 9325, 4128 )
AND ( user_date_created BETWEEN '2013-06-04' AND '2013-06-10' );
I tried to cut my original query one by one, I got a result. Here is the first one:
SELECT * FROM users WHERE user_theme_id IN (9735, 9325, 4128 );
I got 3 rows for this result. See attached snapshot:
Now, the next query that I run is this:
SELECT *
FROM users
WHERE user_date_created BETWEEN '2013-06-04' AND '2013-06-10';
I do get 3 results on this. See attached snapshot:
By the way, this sql that uses BETWEEN should suppose return 4 rows but it only return 3. It doesn't return the data which has the created date of 2013-06-10 08:27:43
What am I doing wrong with my original query Why does it always return an empty rows?
If you are getting results by separately running different where clauses doesn't guarantee that AND 2 where clauses will return an answer.
There has to be intersection of rows to get result while AND.
You should validate your data and see if overlapping exists.
I have able to make it work by not using the SQL BETWEEN operators but instead COMPARISON OPERATORS like: >= || <=
I have read it from W3schools.com, the SQL between can produce different results in different databases.
This is the content:
Notice that the BETWEEN operator can produce different result in different databases!
In some databases, BETWEEN selects fields that are between and excluding the test values.
In other databases, BETWEEN selects fields that are between and including the test values.
And in other databases, BETWEEN selects fields between the test values, including the first test value and excluding the last test value.
Therefore: Check how your database treats the BETWEEN operator!
That is what happened in the issue that I am facing. The first field was being treated as part of the test values and the 2nd field was being excluded. Using the comparison operators give accurate result.