I am trying to create the following table on the apex website but it gives me an error .I tested this in SQL plus and it worked perfectly.
CREATE TABLE job_grade
(Grade_level varchar(2) not null,
lowest_sal number not null,
highest_sal number not null);
INSERT ALL
INTO job_grade
VALUES ('A', 0, 1000)
INTO job_grade
VALUES ('B', 1001, 2000)
INTO job_grade
VALUES ('C', 2001, 3000)
INTO job_grade
VALUES ('D', 3001, 4000)
INTO job_grade
VALUES ('E', 4001, 5000)
SELECT * FROM DUAL;
output:
ORA-00911: invalid character
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 673
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 659
ORA-06512: at "APEX_210200.WWV_FLOW_DYNAMIC_EXEC", line 1829
4. highest_sal number not null);
5. INSERT ALL
6. INTO job_grade
7. VALUES ('A', 0, 1000)
8. INTO job_grade
The issue is with the SQL Workshop in apex. This does NOT work like sqlplus or sqldeveloper. If you click "run" apex will try and run everything as a single statement and this fails if there are multiple statements.
But don't worry, there is a simple workaround. Highlight the statement with the mouse and then click run. That will run only the highlighted statement. So in this case, highlight the CREATE TABLE statement and run it, then highlight the INSERT ALL statement and run it.
For running multiple statements, use "SQL Script" instead.
Do as #Koen said.
Alternatively, run a single CTAS which "combines" CREATE TABLE and INSERT INTO:
SQL> create table job_grade (grade_level, lowest_sal, highest_sal) as
2 select 'A', 0, 1000 from dual union all
3 select 'B', 1001, 2000 from dual union all
4 select 'C', 2001, 3000 from dual union all
5 select 'D', 3001, 4000 from dual union all
6 select 'E', 4001, 5000 from dual;
Table created.
SQL>
Related
Here's teh pbix file https://1drv.ms/u/s!Amd7BXzYs7AVlm0j7IBWB7EZWKIM?e=LTrZMe
I use field parameter
Slice by = {
("Brand", NAMEOF('Product'[Brand]), 0),
("Category", NAMEOF('Product'[Category]), 1),
("Color", NAMEOF('Product'[Color]), 2),
("Continent", NAMEOF('Customer'[Continent]), 3),
("Country", NAMEOF('Customer'[Country]), 4)
}
I add a slicer Month-year
I'd like when I select for the slicer monthyear for example feb 2020, I'd like that in the matrix Brand and category will be renamed as Brand feb 2020 and category feb 2020, is there a way to do it please?
Power BI will not let you dynamically change the name of a label in a column. You could either include the year month as a column as you would in a matrix table.
Or you could add a measure that shows the selected value and put that in a card or multi card visual above the table. The measure would be defined like this:
TimeSelectionLabel =
IF ( HASONEVALUE ( Date[Month] ), SELECTEDVALUE ( Date[Month] ), "" )
In order to rather datas of different sheets, I would like to create graphics.
But to do that i want to do a query statement that take others sheets depending on two things.
Here is the formula that i tried to do this but it didn't worked :
=IF($D$13="name_1";
{QUERY(
IMPORTRANGE("url_1";"sheet_name!range");
"SELECT Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13 WHERE Col1 ='" & $D$10& "'");
"ERROR"});
IF($D$13="name_2";
{QUERY(
IMPORTRANGE("url_2";"sheet_name!range");
"SELECT Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13 WHERE Col1 ='" & $D$10& "'");
"ERROR")};
But this is not working.
I want that, depending on the "name", in the D13 cell, that display the datas the query bellow.
So if it is the "name_1" in the cell D13, that show his datas from his sheet.
Cell D13
Name_1
Cell D10
Datas
That will displays the datas in a table :
Month
Data 1
Data 2...
Date 12
January
12
15
321
February
14
112
45
If I choose an other data in the cell D10 or/and in the cell D13 that will display other datas from other Sheet :
Month
Data 1
Data 2...
Date 12
January
2
47
36
February
54
85
7
I tried with the IFS statement as well but that worked.
Thx for your help !
you can add another where with and for example like this:
=QUERY({IMPORTRANGE("url_2"; "sheet_name!range")};
"select Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13
where Col1 ='"&$D$10&"'
and Col2 ='"&D$1$3&"'")
This is my query but when I run this in oracle apex it gives me the following error:
delete from
(select ename,e1.store_id,e1.sal as highest_sal
from
employees e1 inner join
(select store_id,max(sal) as sal
from employees
group by store_id
) e2
on e1.store_id=e2.store_id
and e1.sal=e2.sal
order by store_id) s
where rowid not in
(select min(rowid) from s
group by highest_sal);
The output is:
ORA-00942: table or view does not exist
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 673
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 659
ORA-06512: at "APEX_210200.WWV_FLOW_DYNAMIC_EXEC", line 1829
4. (select store_id,max(sal) as sal
5. from employees
6. group by store_id
7. ) e2
8. on e1.store_id=e2.store_id
When I run the code in parentheses, which has the alias s alone, it runs without any problems, but when it is placed in this code, it gives an error
updated: My goal is to first group the data according to store_id and get the maximum sal in each, and join it to the main table itself where sal and store_id are the same, and display its name, which The resulting table is called s. Then I want to remove the duplicate rows from the table (which have the same sal) and to do this we group according to highest_sal and select the least rowid between them, and remove those rowId that are not in the subquery. As a result, non-duplicates are obtained. (This is a trick to remove duplicate lines.)
You appear to want to delete all rows with the highest sal for each store_id grouping except for the row in each group with the lowest ROWID.
You can do that with analytic functions. Either:
DELETE FROM employees
WHERE ROWID IN (
SELECT ROWID
FROM (
SELECT RANK() OVER (PARTITION BY store_id ORDER BY sal DESC) AS rnk,
ROW_NUMBER() OVER (PARTITION BY store_id ORDER BY sal DESC, ROWID ASC)
AS rn
FROM employees
)
WHERE rnk = 1
AND rn > 1
);
or:
DELETE FROM employees
WHERE ROWID IN (
SELECT ROWID
FROM (
SELECT sal,
MAX(sal) OVER (PARTITION BY store_id) AS max_sal,
MIN(ROWID) KEEP (DENSE_RANK LAST ORDER BY sal)
OVER (PARTITION BY store_id) AS min_rid_for_max_sal
FROM employees
)
WHERE sal = max_sal
AND ROWID != min_rid_for_max_sal
);
Or, from Oracle 12, with row limiting clauses in a correlated sub-query:
DELETE FROM employees e
WHERE ROWID IN (
SELECT ROWID
FROM (
SELECT sal
FROM employees x
WHERE e.store_id = x.store_id
ORDER BY sal DESC
FETCH FIRST ROW WITH TIES
)
ORDER BY ROWID
OFFSET 1 ROW FETCH NEXT 100 PERCENT ROWS ONLY
);
Which, for the sample data:
CREATE TABLE employees (ename, store_id, sal) AS
SELECT 'A', 1, 1 FROM DUAL UNION ALL
SELECT 'B', 1, 2 FROM DUAL UNION ALL
SELECT 'C', 1, 3 FROM DUAL UNION ALL
SELECT 'D', 2, 1 FROM DUAL UNION ALL
SELECT 'E', 2, 2 FROM DUAL UNION ALL
SELECT 'F', 2, 2 FROM DUAL;
All delete the f row.
db<>fiddle here
My table is as follow
Col1 Col2
11_A 9
12_B 8
13_C 7
14_A 6
15_A 4
The table we need after the query
Col1 Col2 Col3
11_A 0 9
12_B 8 0
13_C 7 0
14_A 0 6
15_A 0 4
My query is
Col3 =
LEFT( 'Table'[Col2],
SEARCH("A", 'Table'[Col1], 0,
LEN('Table'[Col1])
)
)
Go to the query designer Add Column > Custom Column and use the following expression:
Update
You need two expressions (two new columns) for this:
One is:
'Your Column3
=if Text.Contains([Col1], "A") = true then [Col2] else 0
And the second:
'Your Column2
=if Text.Contains([Col1], "A") = false then [Col2] else 0
There are many ways to solve this,
Another easy way I like to do this with no-coding is to use Conditional Columns:
In PBI select Power Query Editor
Select your table on the edge of the screen
Select Add Column tab
Select Conditional Columns...
Name your column
Enter your condition as in the picture
You can add several conditions if you like
Don't forget to format your column to numeric if needed.
see picture
Adding columns using Conditional Column
I have created a What-if analysis where i am deciding the Threshold value to it.
I have an margin% and Actual Margin % and i need to compare both these value with the value of the Threshold.
Like, Threshold= 20%
margin= 3.90%
Actual Margin %= 0.65%
So, i have created a measure where i am calculating the Actual Margin % with Threshold value i.e. x=0.65*20%
Now i need to compare it(x) with the margin i.e. if(margin
I am able to get this both the measure in place but unable to get the final measure with color code.
Note: Threshold level can be changed and the x value should be changed accordingly with the final color code as well.
Create a Parameter called Threshold: min 1 max 100 step 1 (create also the slider by setting the radio button)
Threshold = GENERATESERIES(0; 100; 1)
Create a measure:
Measure = if (SUM('Values'[ Value]) > Threshold[Parameter Value];"Green";"Red")
Add the measure to the table visual and go to the format tool. Go to conditional formatting. select the measure from the combo and set the Background color on.
Now you get a popup. Set to field value and the column to measure.
Result: when sliding your values will change: