[Solved] SQL return 2 columns [closed]
You could always do SELECT (SELECT the_first_select) AS col1, (SELECT the_second_select) AS col2 FROM DUAL 2 solved SQL return 2 columns [closed]
You could always do SELECT (SELECT the_first_select) AS col1, (SELECT the_second_select) AS col2 FROM DUAL 2 solved SQL return 2 columns [closed]
You can use DENSE_RANK(). For example: select id, name, quantity from ( select id, name, quantity, dense_rank() over(order by quantity desc) as rk from t ) x where rk <= 2 DENSE_RANK() computes a number for each row according to an ordering of your choosing. Identical values get the same number, and no numbers are … Read more
If you really what to work only with the time element, the easiest way to so is to employ the ‘SSSSS’ date mask, which returns the number of seconds after midnight. So this query will return double the number of seconds between the two columns: select ( to_number(to_char(atn_inn, ‘sssss’)) – to_number(to_char(acn_inn, ‘sssss’)) ) * 2 … Read more
Select X, Y, NVL(Z, showThis) as Z will return showThis if Z is null in ORACLE Select X, Y, ISNULL(Z, showThis) as Z will return showThis if Z is null in SQL-SERVER 0 solved Condition statement in a select
A partial solution might be SELECT . . . customer.customer_corporate_name, isnull(customer.siren_corp ,Replace(customer.comm_regnum_cust, ‘ ‘, ”)) AS SiretSiren . . . FROM customer JOIN customer_status . . . ON customer_status.status_id = status.status_id ORDER by customer.customer_corporate_name,SiretSiren solved ORDER A TABLE BY TWO COLUMNS
You haven’t given any indication of error message or any details that could help pinpoint your issue. I’m not sure why you have an embedded DECLARE…BEGIN…END, why you need a COMMIT in the middle of the code or why you have a COMMIT at all – it should be committed by the calling procedure. I … Read more
Try this: Open CMD: 1. sqlplus / as sysdba; 2. create user test identified by 123; 3. grant all privileges to test; Here: test is the new user whose password is 123 Now when you need to login with this user Type in CMD: Sqlplus test/123 Correction: In URL: url=”jdbc:oracle:thin:@localhost:1523:system”; the last parameter should be … Read more
You could install Oracle XE. It runs much leaner than a full database install, which is what you have with your Developer Day VirtualBox VM. And yes, you can connect to MySQL – assuming you have the MySQL JDBC Jars and an actual MySQL Database to play with. solved What are different ways to create … Read more
I assume YEAR is an Integer number, best practice would be to have a column type as data, and get the year using the YEAR function in SQL. SELECT CONSUMER_NUMBER FROM CONSUMER_INFO WHERE YEAR(Data) =2014 AND CONT = ‘USA’ AND ROWNUM = 1 ; Something like this, but anyway I don’t think this is the … Read more
Using substr: declare l_start number := DBMS_UTILITY.get_cpu_time; begin for i in ( with t as ( select ‘Chapter ‘ || level || ‘ Unit ‘ || level || ‘ Sect ‘ || level d from dual connect by rownum < 100000 ) select substr(d, 1, instr(d, ‘ ‘, 1, 2) – 1) chapter , substr(d, … Read more
“Now I am getting 9 rows” The outer loop steps through an array of three elements. The nested loop steps through an array of three elements for every element in the outer loop. 3 * 3 = 9. “how to get ‘AA’ ‘BB’ ‘CC’ from below query” Apply Occam’s razor and discard the inner loop: … Read more
No. The block as a whole will get rolled back on failure, but the raise statement on its own does not perform a rollback. For example, this block fails and is implicitly rolled back (exactly as if it was an SQL insert etc): begin insert into demo(id) values(1); dbms_output.put_line(sql%rowcount || ‘ row inserted’); raise program_error; … Read more
SELECT grade, COUNT( DISTINCT CASE WHEN DATE ‘2015-01-01’ >= date_column AND date_column < DATE ‘2016-01-01’ THEN customer_id END ) AS number_of_unique_customers_in_2015, COUNT( DISTINCT CASE WHEN DATE ‘2016-01-01’ >= date_column AND date_column < DATE ‘2017-01-01’ THEN customer_id END ) AS number_of_unique_customers_in_2016 FROM Customers WHERE Date_Column >= DATE ‘2015-01-01’ AND Date_Column < DATE ‘2017-01-01’ GROUP BY grade; … Read more
This will give you all the subs where the Mem and Sub are not the same. SELECT SUB FROM TABLE WHERE MEM <> SUB This will give you a distinct list of Sub’s that, at one point or another, do not have a matching MEM. SELECT DISTINCT SUB FROM TABLE WHERE MEM <> SUB EDIT: … Read more
Here’s a different approach that handles nulls and does not risk altering any data. It uses a with clause to break down the data by the delimiters, ending up with splitting on the commas. ASSUMPTION: Steps have already been taken to ensure that the data has already been scrubbed of the delimiter characters (commas and … Read more