Missing right parenthesis SQL - * [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am having trouble with this piece of code, as it is saying "Error at line 22
ORA-00907: missing right parenthesis" when I execute it.
SELECT DC.ACJ_ID,
DC.MCI_UNIQ_ID,
DG.GENDER_COMMON_DESC,
DR.RACE_COMMON_DESC,
AD.ADDRESS_LINE_1,
AD.ADDRESS_LINE_2,
AD.CITY,
AD.STATE,
AD.ZIP_CD,
AD.ZIP_CD_9,
DC_RANK
FROM DW_CLNTVIEW.FACT_CLIENT_WEEK_LATEST FCAS,
DW.DIM_GENDER DG,
DW.DIM_RACE DR,
DW.DIM_ADDRESS AD,
KLISA.JAIL_IDS DOC,
(SELECT ACJ_ID,
MCI_UNIQ_ID,
DENSE_RANK ()
OVER (PARTITION BY ACJ_ID
ORDER BY END_DATE DESC, EFF_DATE DESC, MCI_UNIQ_ID DESC ---REMOVE “MCI_UNIQ_ID DESC” TO ALLOW DUPLICATES ON ACJ_ID
DC_RANK
FROM DW.DIM_CLIENT) DC
WHERE FCAS.RACE_KEY = DR.RACE_KEY(+)
AND FCAS.SRC_SYS_KEY(+) = 0
AND FCAS.GENDER_KEY = DG.GENDER_KEY(+)
AND FCAS.ADDRESS_KEY = AD.ADDRESS_KEY(+)
AND DC.MCI_UNIQ_ID = FCAS.MCI_UNIQ_ID(+)
AND ACJS.ACJ_ID = DC.ACJ_ID(+)
AND DC_RANK(+) = 1;

You have unbalanced parenthesis.
(SELECT ACJ_ID,
Left.
OVER (PARTITION BY ACJ_ID
Another left.
FROM DW.DIM_CLIENT) DC
Closed one pair.
Thus leaving one open.

Related

How I can resolve the MariaDB problem in SQL in my query? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I use Jupiter notebook with python for using sql so
i have the next error:
': (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE AllPoints > 30000' at line 11")
and
i have this query
query = '''SELECT players.playerID, lastName, SUM(points) AS AllPoints
FROM players
JOIN players_teams
ON players.playerID = players_teams.playerID
GROUP BY lastName, players.playerID
WHERE AllPoints > 30000
'''
puntos = pd.read_sql(query,db)
puntos
I think it is a simple query so I don t know where it is the error.
thanks for helping
You can't use WHERE after GROUP BY but you can use HAVING. Your query should be :
SELECT
players.playerID, lastName, SUM(points) AS AllPoints
FROM
players
INNER JOIN players_teams ON players.playerID = players_teams.playerID
GROUP BY
players.playerID
HAVING SUM(points) > 30000

Unable to left join within a SQL query containing CTEs [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I need to combine the results from two different CTEs into a single table. Hence, I have written the following SQL query wherein I attempted to create a left join on two different fields (patient_id, quarter in example below).
Unfortunately, I am getting a SQL compilation error (Unknown user defined function A.YR_QTR). But I have declared this variable in the code so am at a loss to why this error is cropping up. My code follows below:
WITH op_clms AS
(
SELECT
MC.UNIV_MBR_ID AS univ_mbr_id,
MC.YR_QTR AS YR_QTR,
COUNT DISTINCT MC.ENC_KEY AS op_clms
FROM
CRF.MED_CLAIMS AS MC
WHERE
MC.SERVICE BETWEEN '2016-01-01' AND '2020-12-31'
AND PLACE_OF_SERVICE ! = '23'
),
ed_clms AS
(
SELECT
MC.UNIV_MBR_ID AS univ_mbr_id,
MC.YR_QTR AS YR_QTR,
COUNT DISTINCT MC.ENC_KEY AS ed_clms
FROM
CRF.MED_CLAIMS AS MC
WHERE
MC.SERVICE BETWEEN '2016-01-01' AND '2020-12-31'
AND PLACE_OF_SERVICE = '23'
)
SELECT
a.UNIV_MBR_ID, a.YR_QTR
(IFNULL(op_clms, 0)) AS op_clms,
(IFNULL(ed_clms,0)) AS ed_clms,
1 as cohort
FROM
(SELECT UNIV_MBR_ID, YR_QTR
FROM op_clms
UNION
SELECT UNIV_MBR_ID, YR_QTR
FROM ed_clms) a
LEFT JOIN
op_clms ON a.UNIV_MBR_ID = op_clms.UNIV_MBR_ID
AND a.YR_QTR = op_clms.YR_QTR
LEFT JOIN
ed_clms ON a.UNIV_MBR_ID = ed_clms.UNIV_MBR_ID
AND a.YR_QTR = ed_clms.YR_QTR
Can somebody please guide me on what I am doing wrong? Each of the individual CTEs check out fine on their own. And I cant find anything else syntactically/logically wrong with my code.
It appears in my original code, I inadvertently omitted a comma after a.YR_QTR. Adding that as shown below, fixes the issue!
a.UNIV_MBR_ID, a.YR_QTR,
(IFNULL(op_clms, 0)) AS op_clms,
(IFNULL(ed_clms,0)) AS ed_clms,
1 as cohort

Multi Column Set Null Value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have the following SQL Statement, which gives me an error.
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE + STATUS + STATUSDATE = NULL
WHERE UNIT = '231296' AND BMON = '2020114';
What is wrong with that code?
You can update multiple columns like that:
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE = NULL
,STATUS = NULL
,STATUSDATE = NULL
WHERE UNIT = '231296'
AND BMON = '2020114';

MS-Access - you tried to execute a query Syntax error in JOIN [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Please help, I can't see what I did wrong. But I have 2 group by's
SELECT DISTINCT
SalesmanTable.SalesNum,
(SalesmanTable.SalesFName & ' ' & SalesmanTable.SalesLName),
BusinessInfo.BusinessNum,
BusinessInfo.BusinessName,
BusinessInfo.OwnerName
FROM
((SalesmanTable
LEFT JOIN
OrderInfo ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum])
LEFT JOIN
BusinessInfo ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]
WHERE
OrderInfo.Paid = FALSE
GROUP BY
SalesmanTable.SalesNum, BusinessInfo.BusinessNum
GROUP BY
SalesmanTable.SalesNum,
(SalesmanTable.SalesFName & ' ' & SalesmanTable.SalesLName),
BusinessInfo.BusinessNum, BusinessInfo.BusinessName, BusinessInfo.OwnerName;
This is your FROM clause:
FROM ((SalesmanTable LEFT JOIN
OrderInfo
ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum]
) LEFT JOIN
BusinessInfo
ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]
The parentheses do not balance. So:
FROM (SalesmanTable LEFT JOIN
OrderInfo
ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum]
) LEFT JOIN
BusinessInfo
ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]

SQL: simple custom column in select doesn't work? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
If I add custom column in select, I get this error:
20018 Invalid column name '2'.
Here is query example
SELECT
[msg].[MessageTo],
[msg].[MessageFrom],
[msg].[SendTime],
[msg].[ReceiveTime],
[msg].[id],
'2' AS source,
[kat].[id] AS [CategoriId],
[kat].[naziv] AS [CategoriName]
FROM
[SMSServer_1].[dbo].[MessageIn] AS [msg]
LEFT JOIN [Tekijanka].[dbo].[crm_poruka] AS [por] ON [por].[fk_poruka] = [msg].[id]
AND [por].[fk_source] = [2]
LEFT JOIN [Tekijanka].[dbo].[crm_kategorije_poruka] AS [kat] ON [kat].[id] = [por].[fk_kategorija]
WHERE
msg.id NOT IN (
SELECT
fk_poruka
FROM
Tekijanka.dbo.crm_poruka
WHERE
fk_status <> 1
)
ORDER BY
[SendTime] DESC
Is there any way to fix it?
The problem is in LEFT JOIN, not in the SELECT section:
AND [por].[fk_source] = [2]
This condition tries to join fk_source and column named [2]. Of course, there's no such column in tables MessageIn and crm_poruka. You have to change this part of the code (remove the condition or change it to AND [por].[fk_source] = 2).