CREATE VIEW ["Counties above average NUMBEROFINFECTIONS"] AS
SELECT NAME, TOTALNUMBEROFINFECTIONS
FROM COUNTRY
WHERE TOTALNUMBEROFINFECTIONS > (SELECT AVG(TOTALNUMBEROFINFECTIONS) FROM COUNTRY)
if you are in Oracle or sql server remove brackets:
CREATE VIEW "Counties above average NUMBEROFINFECTIONS" AS ....
brackets only works in sql server :
CREATE VIEW [Counties above average NUMBEROFINFECTIONS] AS ...
however why you name your view that needs tobe escaped , not a good practice at all
Also Bryan Dellinger brought to my attention:
In Oracle 12.2 and above the maximum object name length is 128 bytes.
In Oracle 12.1 and below the maximum object name length is 30 bytes.
Related
Using Advantage SQL, I have the following query:
SELECT TOP 10 mytable.*
FROM "mytable.ADT" mytable
ORDER BY date DESC
This returns this data set:
INDEX NR NAME Date
---------------------------------------------------
"145443" 115 Bob 19.03.2021 12:26
"23545",1 215 Steve 19.03.2021 12:09
"564543","",0 215 John 19.03.2021 12:09
"456234" 215 Mark 19.03.2021 12:09
What I want to do is work with the data in the INDEX column. But if I run a normal SELECT query with this field name:
SELECT mytable.INDEX etc
it doesn't run. I also cannot add it as an alias or anything.
Are there any workarounds to pull the specific column into a SELECT? My goal is to do text manipulation to remove the quote marks and extract only the pure number that sits in the middle.
This is the first time I've had this issue - I'm guessing the word INDEX is somehow a function name which screws things up. But I also am guessing there is a way around it?
Thanks.
INDEX is a SQL keyword -- and probably reserved, which is the problem.
You need to escape it. I believe Advantage supports both double quotes and square braces:
SELECT mytable."INDEX", mytable.[INDEX]
FROM "mytable.ADT" mytable
order by date desc
Note that capitalization is important in some databases (but not Advantage SQL) when you escape column names.
Can I do SQL-style query on an in-memory dataset (or cellarray, or structure, etc) in MATLAB?
Why I ask is, sometimes, I don't want to talk to the database for 1000 times when I want to do different operations on each of the 1000 rows of data. Instead, I'd rather read all 1000 from the database and operate on them in MATLAB.
For example, I have read the following out of from the database:
age first_name last_name income
30 Mike Smith 45
17 David Oxgon 17
22 Osama Lumbermaster 3
Now I want to find out the full names of the people that are under the age of 25. I know how to do it, but is there any syntax as clean and intuitive as SQL like this?
SELECT first_name + ' ' + last_name AS name FROM people WHERE age < income
In the docs page Access Data in a Table (see the example Index Using a Logical Expression) it shows that your examples could be achieved as follows:
MyTable({'first_name','last_name'}, MyTable.age < MyTable.income)
These docs don't specifically explain how to merge the name and surname into one variable but I'm sure it's easy. Give it a try and let us know if you get it.
I have to insert into the table the following rows with a tax type = 1
Indiana 7%
Kentucky 6%
Ohio 5.5%
This is the code I have thus far
insert into sales.salestaxrate
(stateprovinceid,taxtype,taxrate,name)
Values('13','1','0.07','Indiana')
My question is do I need to have the numbers in single quotes or just the name?
Probably not. Most (if not all) SQL systems will implicitly translate the string value to a numeric value.
Note that if the string value is not translatable to a number you will not get an error until run-time:
insert into sales.salestaxrate
(stateprovinceid,taxtype,taxrate,name)
Values(13,1,'Seven Percent','Indiana')
Whereas if you did not use quotes it would not compile.
In the report I'm working with, I need to display information of four columns of a database table. The first three columns of the table are SEX, AGE and NAME. The other N columns (N being like 100!) are questions, with every line of the table meaning that person's answer to that question:
SEX | AGE | NAME | Q1 | Q2 | Q3 | ... | Q100
In my report, I need to show four of these columns, where the first three are always the same and the fourth column varies according to the option selected by the user:
SEX | AGE | NAME | <QUESTION_COLUMN>
So far I've created a dropdown parameter (filled with "Q1", "Q2", "Q3", etc) where the user can select the question he wants to compare. I've tried to use the value of the selected option (for instance, "Q1") in the SELECT clause of my report query, without success:
SELECT sex, age, name, ${QUESTION} FROM user_answers
Pentaho Report Designer doesn't show any errors with that, it simply doesn't show any values for the question column (the other columns - sex, age and name - always return their values)
So, I would like your know:
Can I do this? I mean, use parameters in the SELECT clause?
Is there any other way have this "wildcard" column according to a parameter?
Thanks in advance!
Bruno Gama
you can use the pentaho report design to design.
First,you must bulid the param "QUESTION"on the paramers
eg: SELECT question FROM user_ansewers order by XXXX
you can use the sql
SELECT sex, age, name,question FROM user_answers
where question= ${QUESTION}
last ,you can see the "drop down" to realized the choose
I am using SQL server as database. This problem solves like this :
execute('SELECT sex, age, name, '+${QUESTION}+' as Q1 FROM user_answers')
Please note that ${QUESTION} must be a column name of user_answers. In this example I used a text box parameter name QUESTION where column name is given as input. You may need other coding if input parameter is not text box.
One of my query to Sybase server is returning garbage data. After some investigations i found out that one of the columns with datatype double is causing the issue. If I don't select that particular column then the query returns correct result. The column is question is a double with laarge number of decimal places. I tried to use round function upto 4 decimal places but still i get corrupt data. How can I correctly specify the column in my query to get correct data?
I am using windows 7 box and Sybase Adaptive server enterprise driver. (Sybase client 15.5). I am using 32 bit drivers.
Sample results:
Incorrect result using sybase ASE driver on windows 7 box
"select ric_code as ric, adjusted_weight as adjweight from v_temp_idx_comp where index_ric_code='.AXJO' and ric_code='AQG.AX'"
ric adjweight
1 AQG.AX NA
2 \020 NA
3 <NA> NA
Correct result on windows xp box using Merant driver
"select ric_code, adjusted_weight from v_temp_idx_comp where index_ric_code='.AXJO' and ric_code='AQG.AX'"
ric_code adjusted_weight
1 AQG.AX 0.3163873547
Regards,
Alok
You may try convert to numeric like this:
select ric_code as ric, weight, convert(numeric(16,4), adjusted_weight) as adjweight, currency as currency
from v_temp_idx_comp
where index_ric_code='.AXJO'