SELECT
session_start_dt
,PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY excess_wait)
OVER (PARTITION BY session_start_dt)
FROM Excess_Wait_AB
This query results is following error:
[Teradata Database] [TeraJDBC 15.10.00.22] [Error 3707] [SQLState
42000] Syntax error, expected something like a name or a Unicode
delimited identifier between ')' and the 'OVER' keyword
.
Try
SELECT
session_start_dt
, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY excess_wait) as pcntl
FROM Excess_Wait_AB
This is another option:
SELECT
session_start_dt
, PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY excess_wait) as pcntl
FROM Excess_Wait_AB
Difference between them explained here.
Related
I am trying to use Lead/Lag function in mysql. In lead and lag function there is option to use default value for last non existent row. see documentation below
LEAD(expr [, N[, default]]) [null_treatment] over_clause
In above default value I want to use curdate() function but it is giving error
for example of my query is below
SELECT
AdmissionNo,
PatientShiftDate,
timestampdiff(DAY, PatientShiftDate,
lead(PatientShiftDate, 1 , NOW() )
over ( order by IPDBedAllocationNo) ) as NoofStay
FROM
PatientBedShift
it is giving error
#42000You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' curdate() ) over ( order by IPDBedAllocationNo) ) as NoofStay FROM...' at line 5
I want to calculate number days patient stayed in each room. It is returning null instead it should use curdate(), now() or current_timestamp() function so I can get correct number of days patient stayed in single query.
I have a better-sqlite3 statement that orders and ranks my database, and I have a IN statement so I can select more than 1 row. That is where I run into an issue, I need to fetch multiple rows based on a dynamic array of IDs.
My SQLITE Statement looks like this:
Table.prepare('SELECT *, RANK () OVER (ORDER BY amount DESC) rank FROM table WHERE user IN(?)');
And I try to get from this statement with things like this:
getAll.get(['1','2','3']);
getAll.get('6,9,4');
getAll.get('7','5','8');
I get an error:
RangeError: Too many parameter values were provided
How exactly can I select multiple values without knowing the length of my array (so ?,? won't cut it), and allow as much values as possible? I used ?* and I get a Syntax error.
I am using better-sqlite3 for Node.JS
Instead of IN use the operator LIKE:
SELECT *, RANK () OVER (ORDER BY amount DESC) rank
FROM table
WHERE ',' || ? || ',' LIKE '%,' || user || ',%'
and pass the list as 1 string of comma separated values (without spaces):
all('6,9,4');
I am using the below query and it gives error that "Selected non-aggregate values must be part of the associated group. SELECT Command Failed."
SELECT TOP 100 X_ISP_AFF_ADDR_SEQ, CAST(COUNT(*) AS BIGINT) AS COUNT_ROW FROM S_CONTACT WHERE X_ISP_AFF_ADDR_SEQ NOT LIKE '%[a-zA-Z]%';
I changed the above query as written below but the error still persists.
SELECT TOP 100 X_ISP_AFF_ADDR_SEQ, CAST(COUNT(X_ISP_AFF_ADDR_SEQ) AS BIGINT) AS COUNT_ROW FROM S_CONTACT WHERE X_ISP_AFF_ADDR_SEQ NOT LIKE '%[a-zA-Z]%';
You presumably are missing a GROUP BY clause here:
SELECT TOP 100
X_ISP_AFF_ADDR_SEQ,
CAST(COUNT(*) AS BIGINT) AS COUNT_ROW
FROM S_CONTACT
WHERE
X_ISP_AFF_ADDR_SEQ NOT LIKE '%[a-zA-Z]%'
GROUP BY
X_ISP_AFF_ADDR_SEQ;
The exact error you were seeing with your original query has to do with that selecting X_ISP_AFF_ADDR_SEQ instructs Teradata to return a value for each record in the table, whereas COUNT() returns a value over the entire table. It is not possible (in general) to mix aggregates and non aggregates in a select clause.
It seems so simple; but I can't get this working.
select ISIN, QuoteTimestamp
from QuoteData
where (ISIN, QuoteTimestamp) IN
(select ISIN, MAX(QuoteTimestamp) QuoteTimestamp
from QuoteData
group by ISIN)
This query gives me a syntax error. If I amend it to only use a single column (remove the MAX(QuoteTimewstamp)) it works.
It seems to be correct, as per the documentation.
Adding "AS" for the subquery alias makes no difference.
Here's the full error message from SQLite Manager.
SQLiteManager: Likely SQL syntax error: select ISIN, QuoteTimestamp
from QuoteData
where (ISIN, QuoteTimestamp) IN
(select ISIN, MAX(QuoteTimestamp) AS QuoteTimestamp
from QuoteData
group by ISIN)
[ near ",": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
This seems to work although, to me, it seems counter-intuitive. It is returning "Symbol", "Bid" and "Ask" from the row with MAX(QuoteTimestamp).
select ISIN, Symbol, Bid, Ask, MAX(QuoteTimestamp)
from QuoteData
group by ISIN
I'm sure Oracle and their ilk would tell me that Symbol, Bid and Ask are not group-by expressions.
Thanks for all the help.
Thanks,
Al.
In SQLite 3.7.11 or later, you do not need to use a subquery at all:
select ISIN, MAX(QuoteTimestamp) QuoteTimestamp
from QuoteData
group by ISIN
I have a table SyncTokenLock that has column lockName that is of CLOB type. When I run following query from SQLDeveloper -
select * from SyncTokenLock where
lockName='com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
I get following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 - "inconsistent datatypes: expected %s got %s"
I get similar error when this query is executed through Hibernate (3.6.10) against Oracle 11g. Hibernate throws following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
Any idea what could the reason be.
Correct, you can't use equality with a CLOB in the WHERE clause. But you can do this:
SELECT * FROM SyncTokenLock
WHERE dbms_lob.substr(lockName, 100) =
'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
Does your column really need to be a CLOB? Are you expecting values over 4000 characters? If not, use a VARCHAR2.
Instead of using the equal sign, you may use like:
select * from SyncTokenLock where lockName like 'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';