I keep getting this syntax error:
Syntax error: SELECT list must not be empty at [2:3]
on my SQL query:
Select
FROM 'tfdalissabuck.assessment_01.experiment'
WHERE experiment_cohort = 'treatment' AND minutes_listening_during_experiment > '60'
You need something between SELECT AND FROM, a single or multiple column names.
Also I believe you are using single quotes around the table name, you should be using a tick mark, and if minutes_listening_during_experiment is an integer you can remove the quotes around it
SELECT *
FROM `tfdalissabuck.assessment_01.experiment`
WHERE experiment_cohort = 'treatment'
AND minutes_listening_during_experiment > 60
Related
How do I get the column "count(division)" instead of getting the actual number of counts?
select * from num_taught;
gets me this
select count(division) from num_taught;
gets me this, but I actually want the third column "count(division)" from the previous image
I want to know this because I'm doing this right now:
sql> select * from num_taught as a, num_taught as b
...> where a.count(division) = b.count(division);
Error: near "(": syntax error
but as you can see, there's a syntax error and I think it's because the code is not referencing the "count(division)" columns but actually finding the count instead.
My end goal is to output the "Titles" that have the same "Division" and have the same count(division).
So for example, the end table would have the rows "Chief Accountant", "Programmer Trainee", "Scrivener", "Technician", "Wizard". Since these are the rows that have a match in division and count(division)
Thanks!
What does DESC num_taught return? I am curious how the third column is populated - is it some kind of pseudo-column? You may want try wrapping the column name with [], see: How to deal with SQL column names that look like SQL keywords?
i.e. try:
select [count(division)] from num_taught;
You need to escape your column name using quotes (in case it's Sqlite like you mentioned in the comments).
select "count(division)" from num_taught;
or:
select * from num_taught as a, num_taught as b
where a."count(division)" = b."count(division)";
If you don't you are using the count-function provided by your Database-system.
It's very unusual to name a column like this, it might be either a trap by your tutor or an error while initializing the table in your case.
I think you just want a count(distinct):
select count(distinct division)
from num_taught;
I am trying to split a comma separated column to multiple columns using SQL such that each separated value is under its own column on Snowflake
This is a sample of my table
"2015-01-01","00:52:44",161144,"3.1.0","x86_64","mingw32","Formula","1.1-2","US",1
This is what I have tried:
SELECT * FROM "TUTORIAL"."PUBLIC"."CRAN_LOGS" STRING_SPLIT('date','time','size','r_version','r_arch','r_os','package','version','country','ip_id',';')
This is giving me the error message:
SQL compilation error: syntax error line 1 at position 59 unexpected
''date''. syntax error line 1 at position 149 unexpected ')'.
You are looking for split_part
SPLIT_PART(<string>, <delimiter>, <partNumber>)
Just be careful with column names though. Some of them could be reserved keywords in SQL and might throw an error
with your_table as
(select 'date,time,size,r_version,r_arch,r_os,package,version,country,ip_id' as col)
select split_part(col,',',1) as date,
split_part(col,',',2) as time,
split_part(col,',',3) as size,
split_part(col,',',4) as r_version,
split_part(col,',',5) as r_arch,
split_part(col,',',6) as r_os,
split_part(col,',',7) as package,
split_part(col,',',8) as version,
split_part(col,',',9) as country,
split_part(col,',',10) as ip_id
from your_table;
I have a column and I would like to get a new column using only the first two characters. I would have assumed the following should work, but it throws FROM keyword not found where expected error
SELECT *,
SUBSTR(PHONE_NUMBER , 1,2) AS MY_PHONE_NUMBER
FROM PHONE_NOS;
Try it here
Alias the table and use it in the statement:
SELECT p.*,
SUBSTR(p.PHONE_NUMBER, 1, 2) AS MY_PHONE_NUMBER
FROM PHONE_NOS p;
I have this query
SELECT *
FROM [RawData$]
WHERE 'Temperature[°C]' <= 100
But at the execution I get this error:
Data type mismatch in criteria expression.
The data in this column is 100% integer so I guess there is no problem.
Further this works fine:
SELECT *
FROM [RawData$]
WHERE 'Temperature[°C]'
I also tried this too but then I get no values at all:
SELECT *
FROM [RawData$]
WHERE 'Temperature[°C]' <= '100'
Actually the final question would be:
What query do i need to search a column which name is: Temperature[°C]
[Temperature[°C]][Temperature[[]°C]]
do not work.
This WHERE 'Temperature[°C]' <= 100 compares the literal string Temperature[°C] to the Integer 100.
Use WHERE [Temperature(°C)] < 100 instead.
Note:
square brackets [] are reserved to be wrapped around fieldnames (much like you tried to use single quotes ')
in this particular case, the square brackets in your header get interpreted as normal brackets ().
I think the issue is the column name has square brackets, so you have to maybe do it like this:
SELECT *
FROM [RawData$]
WHERE "Temperature[°C]" <= '100'
With the double quotes, instead. Let me know if that works.
I am trying to use COALESCE in WHERE clause, and I am getting the following error:
ORA-00907: missing right parenthesis Failed SQL stmt:
If I remove the COALESCE, I don't get the error anymore. I am not sure why would it give me this error as the parenthesis seem correct. Here's my SQL statement:
SELECT S.OPRID, A.OPRNAME, S.EMAIL_ADDR
FROM TABLE1 S, TABLE2 A
WHERE COALESCE(S.REHIRE_DT,S.ORIG_HIRE_DT)
BETWEEN (TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM- DD'),'YYYY-MM-DD') - 3 DAY)
AND (TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD') - 1 DAY)
AND S.EMPLSTATUS = 'A'
AND A.EMPLID = S.EMPLID
ORDER BY S.OPRID
Take the "DAY" word out. That is not used in oracle in that manner:
SELECT S.OPRID, A.OPRNAME, S.EMAIL_ADDR
FROM TABLE1 S, TABLE2 A
WHERE COALESCE(S.REHIRE_DT,S.ORIG_HIRE_DT)
BETWEEN (TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM- DD'),'YYYY-MM-DD') - 3 )
AND (TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD') - 1 )
AND S.EMPLSTATUS = 'A'
AND A.EMPLID = S.EMPLID
ORDER BY S.OPRID
"DAY" is a keyword to be used as part of the EXTRACT function - see Here
The default unit of subtraction from a date field is already in units of days. I am not familiar with DB2, but I am assuming that your usage of DAY is a DB2-specific attribute. That is probably not portable SQL. Yes, oracle's error messages can be confusing at times.
Now that I think about it, you can replace all that "TO_DATE" stuff with just:
BETWEEN TRUNC(SYSDATE)-3 AND TRUNC(SYSDATE)-1