I am trying to find the average number of transactions for every product key for the specified time keys. This is the query in DB2.
select
act.product_key
avg(act.cnt) as avg_transaction
from tb1 as ca
inner join tb2 as act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
group by act.product_key, act.time
having act.time in (16476,16516, 16556,16596, 16636,16676,16716, 16756, 16796,16836,16876,16916,16956);
This is the error I am getting for the above query. I am not sure whats going wrong, this is the first time I am querying on DB2. Any suggestions would be great.
Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=(;act.product_key
avg;,, DRIVER=3.66.46
SQLState: 42601
ErrorCode: -104
Error: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-104;42601;(|act.product_key
avg|,, DRIVER=3.66.46
SQLState: 56098
ErrorCode: -727
The way you describe what you want, you should move the having to a where clause and remove the time key from the group by:
select act.product_key, avg(act.cnt) as avg_transaction
from tb1 ca inner join
tb2 act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
where act.time in (16476, 16516, 16556,16596, 16636, 16676, 16716, 16756, 16796, 16836, 16876, 16916, 16956)
group by act.product_key;
I'm not sure if that will fix your problem.
Related
I am sure that you are used to this question but nonetheless I am having trouble with my SQL script. It is very frustrating.
When I execute the SQL against the SAP Hana database, I continuously receive this error:
Errors occurred while executing the SQL statement: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near ")": line 14 col 35
Let me present the SQL concerned here:
SELECT
BKPF.BKTXT, BKPF.MONAT, BSEG.BELNR, BSEG.BUKRS, BSEG.DMBTR, BSEG.GJAHR, BSEG.MANDT, BSEG.PRCTR, BSEG.SAKNR, CEPCT.KTEXT, CEPCT.LTEXT, SKAT.MCOD1, SKAT.TXT20, SKAT.TXT50
FROM
SAPPR1.BSEG
INNER JOIN SAPPR1.BKPF ON BSEG.GJAHR = BKPF.GJAHR
INNER JOIN SAPPR1.CEPCT ON BSEG.PRCTR = CEPCT.PRCTR
INNER JOIN (SELECT
SAKNR, TXT20, TXT50, MCOD1
FROM
SAPPR1.SKAT
WHERE
SPRAS not LIKE '%[a-z0-9 .]%' ) AS SKAT_SUB ON BSEG.SAKNR = SKAT_SUB.SAKNR
WHERE
BKPF.MONAT = (SELECT Month('?')-1)
AND (BSEG.GJAHR = (SELECT Year('?')-1 HAVING Month('?')-1 < 4) OR BSEG.GJAHR = (SELECT Year('?') HAVING Month('?')-1 > 3))
AND BSEG.MANDT = ?
;
Unlike other DBMS HANA does not support selecting records out of nothing.
A SELECT without a FROM is not valid.
In order to create a single-row set one can use the DUMMY table.
SELECT current_date FROM DUMMY;
creates the single-row set with the result of the function expression.
Having said that, for comparisons a set is not required. Instead the function can be directly put into the expression:
WHERE
BKPF.MONAT = (MONTH(?)-1)
Also note that for string typed bind variables no quotation marks are required or allowed.
SELECT
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening AS NumberUniquePatientsWithDepressionScreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years,
[qry_numberofpatientsgreaterthan12withdepressionscreen]![numberofuniquepatientsagegreaterthan12withdepressionscreening] /
[qry_numberofuniquepersonsgreaterthan12years]![numberofuniquepersonsgreaterthan12years] AS PercentageOfPatientsGreaterThan12WithDepressionScreen
FROM
(
tbl_facilityinformation INNER JOIN qry_numberofpatientsgreaterthan12withdepressionscreen ON
tbl_facilityinformation.exportid = qry_numberofpatientsgreaterthan12withdepressionscreen.exportid
)
INNER JOIN qry_numberofuniquepersonsgreaterthan12years ON
tbl_facilityinformation.exportid = qry_numberofuniquepersonsgreaterthan12years.exportid
GROUP BY
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years;
I dont understand why I'm getting the error:
Unable to execute query, invalid operation or syntax using multi-valued field.
I have tried to look for syntax errors but could not find any.
Whenever I am trying to make any change in a product and save it in magento backend I am getting the following error.
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ) AND (p.entity_id = '1696') LIMIT 1' at line 3, query was: SELECT DISTINCT p.entity_id FROM `catalog_product_entity` AS `p` INNER JOIN `catalog_product_flat_1` AS `cpf` ON cpf.entity_id = p.entity_id LEFT JOIN `catalog_category_product` AS `ccp` ON ccp.product_id = p.entity_id WHERE ( () ) AND (p.entity_id = '1696') LIMIT 1
Kindly let me know what is going wrong and how can I resolve this.
There is some inconsistency in database catalog_product_flat_1 table, Please empty all flat tables and try. Please take backup before empty the tables.
I'm needing to create view where I basically have to combine three tables in order to see when a contact was last verified. This is the code I have so far:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW
LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE VERIFIED_ON IS NULL OR
VERIFIED_ON > SYSDATE-365
ORDER BY LASTNAME;
I keep getting this error and can't figure out why.
Error at Command Line:10 Column:7
Error report:
SQL Error: ORA-00904: "VERIFIED_ON": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
If anyone could help I would greatly appreciate it.
You are using verified_on in the where clause. I think you need last_date_verified instead:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT
OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE OC.LAST_DATE_VERIFIED IS NULL OR
OC.LAST_DATE_VERIFIED > SYSDATE-365
ORDER BY LASTNAME;
You can't use a column alias defined in the select clause in the where clause.
Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )