I am facing Analytics Exception while having inner data sets to be combined.
Query:
Select key,days
FROM
(
Select key
FROM sls where id =14004
) AS first
JOIN
(
Select seckey ,days
FROM
(
Select seckey , MAX(opp_days) As days from sls_daily Where id=14004 Group By key
) As f
JOIN
(
Select key,est,cls,days from sls_daily Where dw_cid=14004
) As s
ON f.days = s.days AND f.key= s.key
) AS second
ON second.seckey = first.key
Exception:
AnalysisException: Syntax error in line 15: ) AS first ^ Encountered:
FIRST Expected: IDENTIFIER CAUSED BY: Exception: Syntax error
What is the reason for the error.
Try to avoid reserved words in SQL.
Try like this
Select `key`,`days`
FROM
(
Select `key`
FROM sls where id =14004
) AS `first`
JOIN
(
Select seckey ,`days`
FROM
(
Select seckey , MAX(opp_days) As `days` from sls_daily Where id=14004 Group By key
) As f
JOIN
(
Select `key`,est,cls,`days` from sls_daily Where dw_cid=14004
) As s
ON f.`days` = s.`days` AND f.`key`= s.`key`
) AS `second`
ON `second`.seckey = `first`.`key`
Related
I try to run this code, but I am getting an error:
ParseException line 4:2 missing EOF at 'JOIN' near 'tf_posting'
DELETE
FROM
ez_014315_tap.tf_posting
JOIN (
SELECT
MAX(
FROM_UNIXTIME(
UNIX_TIMESTAMP(dupl_run_ime.run_timestamp)
)
) AS max_run_timestamp
FROM
(
SELECT
geo_zone,
run_timestamp,
COUNT(*)
FROM
ez_014315_tap.tf_posting
WHERE
mandant_id = '001'
AND geo_zone = (
SELECT
DISTINCT geo_zone
FROM
ez_014315_tap.tf_posting
WHERE
mandant_id = '001'
)
GROUP BY
geo_zone,
run_timestamp
) AS dupl_run_ime
) tt1 on tt1.max_run_timestamp = from_unixtime(
unix_timestamp(tf_posting.run_timestamp)
);
Can someone help me to find this missing end of line?
The following Query Works....
SELECT art.cmp_lvl,
(
CURSOR (
SELECT a.cmp_lvl,
(
CURSOR (
SELECT b.cmp_lvl_code,
b.v1 "R_ST",
b.f_name
FROM temp_data b
WHERE b.cmp_lvl = a.cmp_lvl
ORDER BY SEQ
)
) employee
FROM temp_data a
WHERE a.cmp_lvl = art.cmp_lvl
GROUP BY a.cmp_lvl
)
) g_pos_record
FROM temp_data art
WHERE art.report_name = 'EMP_REPORT'
GROUP BY cmp_lvl
ORDER BY cmp_lvl DESC;
Then I simply add another column name as shown below
SELECT art.cmp_lvl,
art.v1 /*ADDED THIS LINE, SHOWS AN ERROR IN THIS LINE */
(
CURSOR (
SELECT a.cmp_lvl,
a.v1 /*ADDED THIS LINE */
(
CURSOR (
SELECT b.cmp_lvl_code,
b.v1 "R_ST",
b.f_name
FROM temp_data b
WHERE b.cmp_lvl = a.cmp_lvl
AND b.v1 = a.v1 /*ADDED THIS LINE */
ORDER BY SEQ
)
) employee
FROM temp_data a
WHERE a.cmp_lvl = art.cmp_lvl
AND a.v1 = art.v1 /*ADDED THIS LINE */
GROUP BY a.cmp_lvl
)
) g_pos_record
FROM temp_data art
WHERE art.report_name = 'EMP_REPORT'
GROUP BY cmp_lvl
ORDER BY cmp_lvl DESC;
Error: ORA-00904: "ART", "V1": Invalid Identifier
00904. 00000 - "%s: Invalid identifier" "Cause
*Action Error at Line 2
I Cannot figure out why. The column added is in the table (for sure).
You aggregate your data to one result row per cmp_lvl (GROUP BY cmp_lvl). Then you want to show the cmp_lvl's v1. However, as there are multiple rows per cmp_lvl that you are aggregating, which row's v1 shall be shown?
Moreover, there is a comma missing after art.v1.
One solution is to decide for one v1, e.g.:
SELECT art.cmp_lvl,
MAX(art.v1),
...
Getting the error for this query which looks valid.
JPA Hibernate native query execution
SELECT
CASE_KEY,
ENCRYPTED_CASE_ID,
FILING_EPOCH_TIME AS CREATION_EPOCH_TIME,
sql2u(SOURCE_LAST_UPDATE_DATETIME) as LAST_UPDATE_EPOCH_TIME
FROM CASE_DIM
WHERE CASE_KEY in (
select * from (
select distinct CASE_KEY
from CASE_TRANSITION_FACT
where CASE_EVENT_KEY BETWEEN :startKey AND :endKey order by CASE_KEY
)
where rownum between :fromRow and :toRow
)
I am working with a tool that would extract some data from an Access Database. So basically, i am working on a query to get this data.
Below is the code i am currently working on.
I am getting an error: Syntax error in FROM clause
I can't seem to find where the query is going wrong. I would appreciate any help! Thank youu.
EDIT: putting my actual query
SELECT table_freq.*, IIF(table_freq.txn_ctr > (table_ave_freq.ave_freq * 3), "T", "F") as suspicious_flag
FROM
(
SELECT tbl_TransactionHistory.client_num, tbl_TransactionHistory.client_name,
tbl_TransactionHistory.transaction_date, Count(tbl_TransactionHistory.client_num) AS txn_ctr
FROM tbl_TransactionHistory
GROUP BY tbl_TransactionHistory.client_num, tbl_TransactionHistory.client_name,
tbl_TransactionHistory.transaction_date
) AS table_freq
INNER JOIN
(
SELECT table_total_freq.client_num, total_txn_ctr as TotalTransactionFrequency, total_no_days as TotalTransactionDays,
(table_total_freq.total_txn_ctr)/(table_no_of_days.total_no_days) AS ave_freq
FROM
(
(
SELECT client_num, SUM(txn_ctr) AS total_txn_ctr
FROM
(
SELECT client_num, client_name, transaction_date, COUNT(client_num) AS txn_ctr
FROM tbl_TransactionHistory
GROUP BY client_num, client_name, transaction_date
) AS tabFreq
GROUP BY client_num
) AS table_total_freq
INNER JOIN
(
SELECT client_num, COUNT(txn_date) as total_no_days
FROM
(
SELECT DISTINCT(transaction_date) as txn_date, client_num
FROM tbl_TransactionHistory
ORDER BY client_num
) AS table1
GROUP BY client_num
) AS table_no_of_days
ON table_total_freq.client_num = table_no_of_days.client_num
)
) AS table_ave_freq
ON table_freq.client_num = table_ave_freq.client_num
What am I doing wrong here?
The result is an error, saying:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'order'.
Msg 156, Level 15, State 1, Line 25 Incorrect syntax near the keyword
'as'.
select *
, Antal + Normtid as Flextid
, SUM(antal) OVER (PARTITION BY transdate ORDER BY tekst)
, x = row_number() over (partition by åruge order by tekst)
from
(
select *
,
(
select b.antal
from bi.dbo.Table_pg_FlextidsopgørelseGlUdgave b
where b.tekst = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.tekst
and b.transdate = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.transdate
and b.åruge = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.åruge
and b.type = 'Normtid'
) as Normtid
from
bi.dbo.Table_pg_FlextidsopgørelseGlUdgave
where type = 'afholdt'
and tekst = 'fs'
--and åruge = '201501'
) as data
order by tekst, transdate
Regards
Peter
It is obvious that you have inappropriate version of Sql Server. Cumulative sums with order by clause like:
SUM(antal) OVER (PARTITION BY transdate ORDER BY tekst)
are only available from Sql Server 2012+.
Actually I can reproduce those errors on Sql Server 2008:
This is on Sql Server 2012:
Notice how the error message changes.
The way you are getting data from derived table is not correct..
EX:
create table
sales
(
id int
)
insert into sales
values
(1),
(2),
(3)
derived table should always have table alias and parent table should refer using from
----this is valid
select
* from
(
select id+1 as id1
from sales
) b
--this is not valid
select
*
(select
id from sales
)b
--Above is valid when you have a subquery say
select
id,(select t1.name from table t1 where t1.id=t2.id)as custname
from table t2
coming to your question..this is not valid.I see both table types are same
select *
,
(
select b.antal
from bi.dbo.Table_pg_FlextidsopgørelseGlUdgave b
where b.tekst = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.tekst
and b.transdate = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.transdate
and b.åruge = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.åruge
and b.type = 'Normtid'
) as Normtid
from
bi.dbo.Table_pg_FlextidsopgørelseGlUdgave
where type = 'afholdt'
and tekst = 'fs'
--and åruge = '201501'
So you can write something like below
select *
, Antal + Normtid as Flextid
, SUM(antal) OVER (PARTITION BY transdate ORDER BY tekst)
, x = row_number() over (partition by åruge order by tekst)
from
(
select * from
(
select b.antal
from bi.dbo.Table_pg_FlextidsopgørelseGlUdgave b
where b.tekst = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.tekst
and b.transdate = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.transdate
and b.åruge = bi.dbo.Table_pg_FlextidsopgørelseGlUdgave.åruge
and b.type = 'Normtid'
and b.type='afholdt'
and b.tekst = 'fs'
) as Normtid
order by tekst, transdate