SELECT TOP query in HANA
Hi,
Can somebody give me the HANA equivalent of the following SQL query:
SELECT TOP (731-624+1) COLUMNNAME FROM TABLENAME
In case of HANA, it gives syntax error near "(".
Hi Yash,
As per the HANA SQL syntax supported case is
<select_clause> ::= SELECT [TOP <unsigned_integer>] [ ALL | DISTINCT ]
<select_list>
After Top only an unsigned intger is expected and cannot handle an <expression> like in your example.
Hope this is useful.
Best Regards,
Ranjit
Similar Messages
-
Hi All..
We are trying to create a Universe (using IDT-Version4.0) on top of the HANA Calculation view. The Calculation view has 4 input parameters, So
in Universe side we have created the respective prompts. For the creation of derived table we have used the following code
SELECT *
FROM "_SYS_BIC"."<schema_name>.<CV_Calculation_View_test>"
'PLACEHOLDER'=('$$IP_A$$','@Prompt(A)'),
'PLACEHOLDER'=('$$IP_B$$','@Prompt(B)'),
'PLACEHOLDER'=('$$IP_C$$','@Prompt(C)'),
'PLACEHOLDER'=('$$IP_D$$','@Prompt(D)')
While validating the above code we are getting an error.
I have attached the snapshot of that error for your reference. Please find the attachment and help me in resolving it.
Thanks in advance.Hello George,
I don't have any personalization set on the info space. Also I am using mapped Account in BI to connect to HANA. The confusing part is that it is able to validate the infospace with the input parameters and index it. However query does not return any results. I even tried running the same query which explorer sends to HANA in the SQL editor and there too the same results,the query does not return anything. The model does return data when I do a data preview and if accessed from other tools like AAO.
Also when I use SSO connection to HANA, indexing of the infospace fails. Where can I see the error log?
Thanks, -
How to select top one in CDS view ?
I have tried following logic to select top one in CDS view but its giving error -
define view Cds_View_First_Reference as select top one CReferredObject from CDSVIEWCROSSREFHi Ruchi,
since you posted this question in "ABAP in Eclipse" I assume you are asking about CDS in ABAP. This is important because the CDS features sets in ABAP and (native) HANA are different.
Be that as it may,, SELECT TOP 1 is neither supported in the CDS implementation in ABAP nor in HANA.
In ABAP you might consider using the min() or max() function together with the appropriate GROUP BY clause in the CDS view (depending on what you want to achieve), but you can also easily "implement" this in the Open SQL statement which selects from your CDS view.
Using the additions SELECT SINGLE or UP TO 1 ROWS and an appropriate ORDER BY clause in Open SQL, you can achieve the same as SELECT TOP 1.
Unfortunately there is currently no possibility to define a view which delivers the TOP 1 which you can again use in another view ("view on view").
Kind regards
Chris -
Prepared Statement, executing SELECT TOP in Ms Access
I'm having the following problem. I built an application fetching data without any problem from MS SQL Server, this was using prepared statements. Now i'm having this strange problem with the following query:
SELECT TOP 1 *
FROM table
WHERE appliance_id = ?
AND ttimestamp_initpk <= ?
AND ((Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?))
ORDER BY ttimestamp_initpk DESC
While on SQL Server this fetches just a record, on MS Access it fetches the whole set of records without worrying about TOP instruction.
That is, it acts like a SELECT * FROM, and this slows down runtime behaviour.
I'm using sun.jdbc.odbc.JdbcOdbcDriver, is it the problem?
Thanks, MirkoThanks for your answer, but i'm not sure this is the reason.
I made one more test: i wrote a .Net application connecting to a MS Access using an ODBC connection. SELECT TOP statement is working fine, so i think i'll try another JDBC driver. Any other solution??
Thanks,
Mirko -
ALTERNATIVE FOR 'SELECT TOP STATEMENT
HI FRIENDS
IF ANY ONE KNOWS HOW TO CONVERT THE SQL STATEMENT GIVEN BELOW PLEASE HELP ME
SELECT TOP 1 CardID FROM EasyRechargeMaster WHERE CardGroup = EasyRecharge.CardGroup
THANKS & REGARDSCheck this query. It should give you desired results....Are you sure about that? Does TOP 1 mean "whatever happens to be the first row fetched"?
-
Can you select another query in a query?
i.e. SELECT A.FIELD1, <PSQUERYNAME>, A.FIELD2
I'm trying to select the results of a select, e.g.
SELECT A.FIELD1, (SELECT B.FIELDB FROM TABLE2 B) FROM TABLE1 A
and it was suggested that I might be able to do this by making the embedded SELECT a separate query and then referencing it. Is this possible? If not, is there another way to do this within PS Query?
Thanks.
MikeYes, that makes sense - but how can I construct this in the PS Query tool? The top level of the query asks you to pick a record, and then select record fields - I see no option that would enable me to select a query or the (one-row single field) result of a query.
e.g., how would I code
SELECT
A.BIRTHDATE,
(SELECT B.DUMMY FROM DUAL B)
FROM PS_PERSON A -
Oracle 10g Select Top 100 Percent
Hello
How to convert MS sql 2008 select top 100 query Oracle PL/SQL ? MY sample MSSQL select query
SELECT TOP (100) PERCENT dbo.Operations.OpID, dbo.CompanyInfo.Name AS CompanyName, dbo.CustomerInfo.SubscriberNo, dbo.CustomerInfo.FirstName,
dbo.CustomerInfo.LastName, dbo.Operations.OpDate, dbo.Operations.BillCount, dbo.Operations.TotalAcceptedCash, dbo.Operations.KioskID,
dbo.Operations.ReceiptNo, dbo.Operations.KioskOpID, dbo.KioskInfo.Name AS KioskName, dbo.Operations.TotalBill, dbo.Operations.TotalPayBack,
dbo.CompanyInfo.CompanyID, dbo.Operations.ConfirmedRecord, dbo.PayMethod.ACK AS PayMethod
FROM dbo.Operations INNER JOIN
dbo.CustomerInfo ON dbo.Operations.SubscriberNo = dbo.CustomerInfo.SubscriberNo INNER JOIN
dbo.CompanyInfo ON dbo.Operations.CompanyID = dbo.CompanyInfo.CompanyID INNER JOIN
dbo.KioskInfo ON dbo.Operations.KioskID = dbo.KioskInfo.KioskID INNER JOIN
dbo.PayMethod ON dbo.Operations.PayMethodID = dbo.PayMethod.PayMethodID
ORDER BY dbo.Operations.OpDate DESCHi,
Please read SQL and PL/SQL FAQ
Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
From what I have found on MS SQL documentation it seems that TOP keyword limits the output to a specified percentage of total number of rows. In your case, having specified 100, you are returning 100% of rows.
So you can simply remove *TOP (100) PERCENT*
Regards.
Al -
Select Top 10 when it includes a GroupBy
I frequently use Select Top 10... to test a query before running it on a large MSSQL database. Works fine, except when the query includes a Group By Clause when it then seems to take as long as not using Top 10. I suspect this is beause it is actually
reading the whole table to get the top 10 Group Bys, whereas all I wanted was for it read the first 10 records and Group the result. Is there a way to write so that it does that
Gerry Mescalsample code ..modify and try this SELECT a.*
FROM
SELECT a.*, ROW_NUMBER() OVER(PARTITION BY m.[col1] ORDER BY m.[col2] DESC) an
FROM [table] a
) a
WHERE a.an <= 10
ORDER BY m.[col2] DESCmark as answer if it is useful -
Update with Select top n statement
Hi All,
Can I use update statemet like this..
Update table1
set Name=(select top (100) t2.name from table2 t2 where table1.ID=t2.ID)
Please let me know ASAP its very urgent
Thanks in Advance
RH
sqlHi sql9 !
You might need below query;
CREATE TABLE Table1 (ID INT,Name VARCHAR(10))
CREATE TABLE Table2 (ID INT,Name VARCHAR(10))
--TRUNCATE TABLE Table1
--TRUNCATE TABLE Table2
INSERT INTO Table1
SELECT 1,'ABC' UNION ALL
SELECT 2,'DEF' UNION ALL
SELECT 3,'GHI'
INSERT INTO Table2
SELECT 1,'JKL' UNION ALL
SELECT 1,'MNO' UNION ALL
SELECT 2,'PQR' UNION ALL
SELECT 2,'STU' UNION ALL
SELECT 3,'VWX' UNION ALL
SELECT 3,'YZ'
UPDATE Table1 SET Name = (SELECT TOP 1 T2.Name FROM Table2 T2 WHERE Table1.ID = T2.ID)
SELECT * FROM Table1
--ID Name
--1 JKL
--2 PQR
--3 VWX
--You can simply re-write your SQL with below query and you don't have to specify TOP Clause inside subquery
UPDATE T1 SET T1.Name = T2.Name
FROM Table1 T1
INNER JOIN Table2 T2 ON T2.ID = T1.ID
SELECT * FROM Table1
--ID Name
--1 JKL
--2 PQR
--3 VWX
Note : In your first query TOP 100 returning more than 1 value from subquery which is not allowed.
Please let me know if this doesn’t work for you. Hope I have answered you correctly.
Thanks,
Hasham -
What's wrong with this query?
SELECT TOP 8 WEEK_END_DATE FROM M_CAL ORDER BY WEEK_END_DATE DESC
Gettgin an error FROM keyword not found where expected...Hi,
Can you tell us what is that TOP 8 ?
Is it a function?
Try this code,
SELECT *
FROM (SELECT WEEK_END_DATE FROM M_CAL ORDER BY DESC)
WHERE ROWNUM < 9;With Best Regards,
Vijayasekaran.N -
hi,
pls I have this issue that needs to be resolved. I need to select top five rows from a table depending on the values of a column stock_value. pls I will appreciate if someone can help me out, Francois pls try and help
This is the senerio:
I have a table stock, on the table I have company_name, stock_value, sector.
Now I want to get top five rows from this table depending on the five highest value of stock_value and for each sector.
lets try and write a query that will retrive the records after that I will put it in a procedure.
I know am suppose to ask this on mssql forum but most mssql forums takes time to reply and this is very urgent cos I have to deliver in 45 minutes time
thank you very much
jideoforhy,
try out:
select s.name, sp. sp_sales total_sales
from salesperson s,
(select salesperson_id,sum(tot_sales) sp_sales
RANK() OVER (ORDER BY SUM(tot_SALES) desc) SALES_RANK
FROM ORDERS
WHERE YEAR = 2006
group by salesperson_id) sp
where sp.sales_rank <= 5 (...n)
and sp.salesperson_id = s.salesperson_id
order by sq.sales_rank;
give result in:
name total_sales
a 100
b 90
c 80
d 70
e 60
hope help you
regards -
Hi,
I want to get the top 10% of salaries in employees table. But I got error:
SQL> select top 10 percent salary
2 from employees
3 order by salary desc;
ORA-00923: FROM keyword not found where expectedHow can I get the top 10% percent?
Thanks a lotHi,
998093 wrote:
... What if I want to get, for example, the employees who are in the top 12% of the salaries? here we cannot use deciles (maybe we can but it won't be very nice).Actually, you can. How nice it will be depends on your data and your exact requirements.
Earlier, we said that the top 10% was the 10th of 10 buckets.
We could say that the top 12% is the last 12 of 100 buckets:
WITH got_tenth AS
SELECT last_name, salary
, NTILE (100) OVER (ORDER BY salary) AS hundredth
FROM hr.employees
SELECT last_name, salary
FROM got_tenth
WHERE hundredth > 100 - 12
ORDER BY salary DESC
;I won't clutter up this message by showing the results for every query; I'll just report the total number of rows. The query I posted earlier (for the top 10%) produced 10 rows of output; the query immediately above produces 12. That's starting to bother me. There are 107 rows in hr.employees. (They all have a salary; don't forget to deal with NULLs in general.) The top 10% should contain 107 * .1 = 10.7 rows. Of course, this has to be rounded to an integer, so it would have been a little better if the top 10% showed 11 rows (since 11 is closer to 10.7 than 10 is), but it's not a real big problem. Likewise, the top 12% should have 107 * .12 = 12.84 rows, so 13 rows of output might be better, but 12 rows isn't too bad.
Now say we want to simplify the condition "WHERE hundredth > 100 - 12". Instead of taking the last 12 buckets in ascending order, let's take the first 12 buckets in descending order:
WITH got_tenth AS
SELECT last_name, salary
, NTILE (100) OVER (ORDER BY salary DESC) AS hundredth
FROM hr.employees
SELECT last_name, salary
FROM got_tenth
WHERE hundredth <= 12
ORDER BY salary DESC
;The result set now contains 19 rows! Why? Because NTILE puts extra items (when there are extras) in the lower-numbered buckets. When there were 10 buckets, then buckets 1 trough 7 had 11 items each, and buckets 8 through 10 had 10 items. We were only dispolaying bucket #10, so we only saw 10 items. Now that there are 100 buckets, buckets 1 through 7 will have 2 items each, and buckets 8 through 100 will have 1 item each. When we numbered the buckets in ascending order, and took the last 12 buckets, we wound up with 12 * 1 = 12 rows, but when we numbered the buckets in descending order and took the first 12 buckets, we got (7 * 2) + (5 * 1) = 19 rows.
When you have R rows and B buckets, and R/B doesn't happen to be an integer, then NTILE will distribute the rows as equally as possible, but some rows will have 1 item more than others. When the ratio R/B is high, that might not be very significant, but when R/B gets close to 1, then you have situations like the one above, where the bigger buckets, although they have only 1 more item than the smaller buckets, are twice as big. Even worse is the situation where R/B is less than 1; then the last buckets will have 0 items.
So, as you noticed, NTILE isn't a good solution for all occasions. Here's a more accurate way, using the analytic ROW_NUMBER and COUNT functions:
WITH got_analytics AS
SELECT last_name, salary
, ROW_NUMBER () OVER (ORDER BY salary DESC) AS r_num
, COUNT (*) OVER () AS n_rows
FROM hr.employees
SELECT last_name, salary
FROM got_analytics
WHERE r_num / n_rows <= 12 / 100
ORDER BY salary DESC
;This produces 12 rows.
If you want 13 rows (because 107 * .12 = 12.84 is closer to 13), then you can change the main WHERE clause like this:
WITH got_analytics AS
SELECT last_name, salary
, ROW_NUMBER () OVER (ORDER BY salary DESC) AS r_num
, COUNT (*) OVER () AS n_rows
FROM hr.employees
SELECT last_name, salary
FROM got_analytics
WHERE r_num <= ROUND (n_rows * 12 / 100)
ORDER BY salary DESC
; -
Provider Speicifc Properties on MultiCube and constant Selection in Query
Hi Experts
I are using BI 7.0, just upgraded to SP24 and having an issue with a MultiPrvider. All of this worked great before the upgrade. Here are the symptoms I am experiencing. This MultiCube has 2 InfoObjects where "Provider-Specific Properties" are set with a constant value.
1) If I display data on MultiCube I can only get consistent results if I chose for "Field Selection for Output" and select All SID fields. If I don't get any results if SID fields are not selected for display.
2) Query on on MultiCube has a Res. Key Fig. using constant selection on Infoprovider plus other Infoobjects. When I execute I get a dump with errors Brain 222 ( referencing the 2 objects that are set as constant on MultiCube, as well as Brain 635 . I have researched both have not yet found anything helpful. Query does execute if I take off the constant select on Infoprovider but then don't get results I want.
I have tried to re-activate MultiCube. I got warnings on CMP error and inconsistency and messages R7I 114, R7I 127 but activation was successful.
I would be very grateful for any suggestions.
Thanks so much.Can you try log out and re-login??
As well when you display DATA, first of all
1. it ask you select necessary field before you go for FIELD OUTPUR FOR SELECTION
2. Overthere in SELECTION top menu, SELECT the second SELECTION menu, and select option "SELECT CHARACTERISTICS" which is the first one.
3. THen enter
4. now you go to the screen for FIELD OUTPUT FOR SELECTION, in that Select 4th option "SELECT ALL CHARACTERISTICS"
and then execute..
just give a try..
not sure how far it helps..
May i know the restriction which stops you running the query..?
try the constant selection on only one object and try...
Edited by: SAP BI Learner on Oct 28, 2011 5:30 AM -
Convert "select top 5 ..." in Oracle8i
-- We are in the process of migrating application from SQLserver7 to Oracle8i,
-- and trying to convert a procedure to return top 5
-- rows given a search string.
-- In SQLserver7, "select top 5 ... "
-- The Oracle8i Application Developer's Guide - Fundamentals
-- recommends to use rownum, the query runs OK in SQL*Plus,
-- but gets error when used in a procedure with returned cursor.
-- Is there any solution for it?
-- Following is the sample query and procedure (in a package)
-- Query returns top 5 rows
select t.rank, t.productid, t.productname
from (
Select score(0) as rank, productid, productname
from Product
where status = 'A'
and contains(productname, 'Frog', 0) > 0
order by rank desc, productid
) t
where rownum < 6;
-- Proc Name: Pr_Test
-- Purpose: Retrieve product data for a specified search string
CREATE OR REPLACE PACKAGE pkg_test
IS
TYPE RT1 IS RECORD (
Rank NUMBER(10),
ProductID Product.ProductID%TYPE,
ProductName Product.ProductName%TYPE
TYPE RCT1 IS REF CURSOR RETURN RT1;
PROCEDURE pr_test
(i_searchstring IN VARCHAR2 ,
io_prdcursor IN OUT RCT1);
END pkg_test;
CREATE OR REPLACE PACKAGE BODY pkg_test
AS
PROCEDURE pr_test
(i_searchstring IN VARCHAR2 ,
io_prdcursor IN OUT RCT1)
IS
BEGIN
OPEN io_prdcursor FOR
select t.rank, t.productid, t.productname
from (
Select score(0) as rank, productid, productname
from Product
where status = 'A'
and contains(productname, i_searchstring, 0) > 0
order by rank desc, productid
) t
where rownum < 6;
END pr_test;
END pkg_test;
-- Following is the error message when compiling the package body:
Warning: Package Body created with compilation errors.
SQL> show error
Errors for PACKAGE BODY PKG_TEST:
LINE/COL ERROR
19/7 PLS-00103: Encountered the symbol "ORDER" when expecting one of
the following:
) * & - + / mod rem with an exponent (**) and or group having
intersect minus start union where connect | |
The symbol ")" was substituted for "ORDER" to continue.
20/11 PLS-00103: Encountered the symbol ")" when expecting one of the
following:
. ( , * @ % & - + ; / for mod rem an exponent (**) asc desc
| |
-- Run the procedure and get the results
declare
i number := 0;
v_string varchar2(50) := 'CAT';
-- v_string varchar2(50) := 'FROG%';
v_RC1 pkg_test.RCT1;
v_Score NUMBER(10);
v_ProductID Product.ProductID%TYPE;
v_ProductName Product.ProductName%TYPE;
begin
pkg_test.pr_test (v_string, v_RC1);
LOOP
FETCH v_RC1 INTO v_Score,v_ProductID,v_ProductName;
EXIT WHEN (v_RC1%NOTFOUND);
DBMS_OUTPUT.put_line(substr('Score='| |v_score| |', ProdID='| |v_ProductID ,1,255));
i := i + 1;
END LOOP;
DBMS_OUTPUT.put_line('Total '| |i| |' records retrieved.');
end;
nullhttp://www.orafaq.org/faqsql.htm#TOP
This may be of use, the plsql cursor declaration syntax may not have all the facilities of runnning the query from sqlplus:
How does one select the TOP N rows from a table?
Form Oracle8i one can have an inner-query with an ORDER BY clause. Look at this example:
SELECT *
FROM (SELECT * FROM my_table ORDER BY col_name_1 DESC)
WHERE ROWNUM < 10;
Use this workaround with prior releases:
SELECT *
FROM my_table a
WHERE 10 >= (SELECT COUNT(DISTINCT maxcol)
FROM my_table b
WHERE b.maxcol >= a.maxcol)
ORDER BY maxcol DESC;
Turloch -
Selecting TOP 20 Products per Catagory
Hi
I'm trying to select the TOP 20 Products per Catagory out of my Star Topology Database
if someone would PLEASE be able to help me out.
Here is my Query: -
SELECT Distinct (SELECT TOP 20 DP.[Description]), DP.Mims_Sub_Cat, SUM(FD.Cost) AS 'Cost'
FROM DIM_Product DP, FACT_Dispensary FD, DIM_Time DT, DIM_Client DC
WHERE DP.Product_KEY = FD.Product_Key
AND FD.Time_KEY = DT.Time_KEY
AND FD.Client_Key = DC.Client_KEY
AND DT.[Year] = 2007
AND DT.[Month] IN (2)
AND Client_name LIKE '%Medicare%'
AND DP.Manufacture_Name LIKE '%Cipla%'
--AND DP.[Description] IN (SELECT TOP 20 [Description])
AND DP.Mims_Sub_Cat IN (SELECT Mims_Sub_Cat)
GROUP BY DP.Mims_Sub_Cat, DP.[Description], FD.Cost
ORDER by DP.Mims_Sub_Cat, SUM(FD.Cost) DESC
My other problem is that it keeps on selecting the same products although i have a distinct in my query
The query will select a product with the amount and then select the same product again with a different amount.
Example :-
Product Descripion Catagory Cost
ULTAK TABS 150MG 60 Acid Reducers 384.94
ULTAK TABS 150MG 60 Acid Reducers 85.54
ULTAK TABS 150MG 60 Acid Reducers 56.98What about:
SELECT * FROM
SELECT DP.[Description], DP.Mims_Sub_Cat, SUM(FD.Cost) AS 'Cost',
RANK() OVER(PARTITION BY DP.Mims_Sub_Cat
ORDER BY SUM(FD.Cost)) AS RANKedColumn
FROM DIM_Product DP, FACT_Dispensary FD, DIM_Time DT, DIM_Client DC
WHERE DP.Product_KEY = FD.Product_Key
AND FD.Time_KEY = DT.Time_KEY
AND FD.Client_Key = DC.Client_KEY
AND DT.[Year] = 2007
AND DT.[Month] IN (2)
AND Client_name LIKE '%Medicare%'
AND DP.Manufacture_Name LIKE '%Cipla%'
AND DP.Mims_Sub_Cat IN (SELECT Mims_Sub_Cat)
) SUbquery
WHERE RankedColumn <=20
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
Maybe you are looking for
-
Time Machine Backing Itself up On Time Capsule
I'd posted this in the Mtn Lion discussion area, but figured I'd see if I got any thoughts from the Time Capsule Area... I have two separate computers exhibiting the same behavior: When I use a USB external drive on either computer for a backup disk,
-
I want to install FCS2 (just the applications) on my computer's HD, and the media it comes with on my external drive. How would I go about doing this?
-
Hi Gurus, Can some one please let me know where can i find the workflow initiator details/query. like who initiated the workflow in the workflow tables Thanks Raghava
-
what is the Advantages of using Runnable Interface and the Thread Class? Please let me know this....and when to use which one.. Thanks satish
-
just downloaded ard from the app store and so no problems with my imac, mac mini or my mac air the trouble is trying to connect it is showing up in the local network scanner the ip address anyway, but just wont connect to my sony vaio running win7 ho