Hello I am trying to create a view, but I keep getting an error no matter what I do. Additionally, I'm using BigQuery.
The error is: Unexpected string literal "DeathCountPerCountry" at [1:13], or with backticks or Table "DeathCountPerCountry" must be qualified with a dataset (e.g. dataset.table). I'm a beginner and I'm stuck please help!
Create View "DeathCountPerCountry"
AS
SELECT Location, MIN(cast(total_deaths AS integer)) AS lowestdeathcount
FROM `sql-covid-project.covid_data.covid_worldwide`
WHERE continent is not null
Group by location
## order by lowestdeathcount desc
Detailed above I tried backticks and "" and neither let me make the view.
you need a dataset into which to place your view. It looks like you have a dataset called covid_data so try this
Create View covid_data.DeathCountPerCountry
AS
SELECT Location, MIN(cast(total_deaths AS integer)) AS lowestdeathcount
FROM `sql-covid-project.covid_data.covid_worldwide`
WHERE continent is not null
Group by location
Related
I'm trying to create a view with the following code:
CREATE VIEW School_Rating (School_Name, Safety_Rating, Family_Rating,
Environment_Rating, Instruction_Rating, Leaders_Rating, Teachers_Rating)
AS
SELECT
NAME_OF_SCHOOL,
Safety_Icon,
Family_Involvement_Icon,
Environment_Icon,
Instruction_Icon,
Leaders_Icon,
Teachers_Icon
FROM CHICAGO_PUBLIC_SCHOOLS
Unfortunately, I keep getting an error, telling me that "Safety_Icon" is not valid in this context
Now it's working...
CREATE VIEW School_Rating (School_Name, Safety_Rating, Family_Rating,
Environment_Rating, Instruction_Rating, Leaders_Rating, Teachers_Rating)
AS SELECT
NAME_OF_SCHOOL,
"Safety_Icon",
"Family_Involvement_Icon",
"Environment_Icon",
"Instruction_Icon",
"Leaders_Icon",
"Teachers_Icon"
FROM CHICAGO_PUBLIC_SCHOOLS
I encounter some problems that i don't understand with APEX.... Well, let's be specific.
I ve got a select element retrieving a top 50 of most liked url (P11_URL). This is populate by a table view, TOp_Domains.
I create an element called "Context" that have to print all text containing the URL selected by the user from the element select. Those Texts come from another table, let's say "twitter_post".
I create a dynamic action (show only) with this sql/statement:
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%:P11_URL%'
group by TXT, NB_RT, RANK
.... and it doesn't work... I think APEX don't like like clause... But i don't know how to do. Let's keep in min an url could have been shared by multiple Tweets, that's why this element "context" is important for me.
I tried to bypass the problem by building a State (in french Statique) and a dynamic action that will refresh the state but it doesn't work neither... bouhououououou
TriX
Right click on the 'P11_URL' and create DA. Event :change, Item:P11_URL. As the true action of the DA, select 'Set Value'. Write your query in the sql stmt area. In the page items to submit, select 'P11_URL' . In the 'Affected Items': select 'Context'.
Query should be :
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%' || :P11_URL || '%'
group by TXT, NB_RT, RANK
So
Thanks to #Madona... Their example made me realised my mistake. I wrote the answer here for futher help if somebody encouter the same porblem.
A list select element get as arguments a display value (the one you want to be shown in your screen.... if you want so....^^ ) and a return value (in order, I think to linked dynamic actions). So to solved my problem i had to shape my sql statement as:
select hashtags d, hastags r
from my table
order by 1
[let s say that now in Apex it s an object called P1_HASHTAGS]
First step problem solving.
In fact, the ranking as second value, as i put into my sql statement was making some mitsakens into my 'Where like' clause search... well... Newbie am i!
Second step was to correctly formate the sql statement receiving the datas from my select lov (P1_HASHTAGS) into my interactive report. As shown here:
Select Id, hashtags
from my table
where txt like '%'||:P1_HASHTAGS||'%'
And it works!
Thank you Madona your example helped me figure my mistakes!
I am working on a web app and there are some long winded stored procedures and just trying to figure something out, I have extracted this part of the stored proc, but cant get it to work. The guy who did this is creating alias after alias.. and I just want to get a section to work it out. Its complaining about the ending but all the curly brackets seem to match. Thanks in advance..
FInputs is another stored procedure.. the whole thing is referred to as BASE.. the result of this was being put in a temp table where its all referred to as U. I am trying to break it down into separate sections.
;WITH Base AS
(
SELECT
*
FROM F_Inputs(1,1,100021)
),
U AS
(
SELECT
ISNULL(q.CoverPK,r.CoverPK) AS CoverPK,
OneLine,
InputPK,
ISNULL(q.InputName,r.InputName) AS InputName,
InputOrdinal,
InputType,
ParentPK,
InputTriggerFK,
ISNULL(q.InputString,r.InputString) AS InputString,
PageNo,
r.RatePK,
RateName,
Rate,
Threshold,
ISNULL(q.Excess,r.Excess) AS Excess,
RateLabel,
RateTip,
Refer,
DivBy,
RateOrdinal,
RateBW,
ngRequired,
ISNULL(q.RateValue,r.RateValue) AS RateValue,
ngClass,
ngPattern,
UnitType,
TableChildren,
TableFirstColumn,
parentRatePK,
listRatePK,
NewParentBW,
NewChildBW,
ISNULL(q.SumInsured,0) AS SumInsured,
ISNULL(q.NoItems,0) AS NoItems,
DisplayBW,
ReturnBW,
StringBW,
r.lblSumInsured,
lblNumber,
SubRateHeading,
TrigSubHeadings,
ISNULL(q.RateTypeFK,r.RateTypeFK) AS RateTypeFK,
0 AS ListNo,
0 AS ListOrdinal,
InputSelectedPK,
InputVis,
CASE
WHEN ISNULL(NewChildBW,0) = 0
THEN 1
WHEN q.RatePK is NOT null
THEN 1
ELSE RateVis
END AS RateVis,
RateStatus,
DiscountFirstRate,
DiscountSubsequentRate,
CoverCalcFK,
TradeFilter,
ngDisabled,
RateGroup,
SectionNo
FROM BASE R
LEFT JOIN QuoteInputs Q
ON q.RatePK = r.RatePK
AND q.ListNo = 0
AND q.QuoteId = 100021 )
Well, I explained the issue in the comments section already. I'm doing it here again, so future readers find the answer more easily.
A WITH clause is part of a query. It creates a view on-the-fly, e.g.:
with toys as (select * from products where type = 'toys') select * from toys;
Without the query at the end, the statement is invalid (and would not make much sense anyhow; if one wanted a permanent view for later use, one would use CREATE VIEW instead).
This view is what I am working on. It works fine,
but I intend to add the COALESCE statement in the commented
out portion to this Script. Would anyone know how to write the
Script properly. When I combined them, there was an error.
CREATE VIEW [dbo].[VW_Bzo_D]
AS WITH today AS
(SELECT *
FROM [dbo].[Bz_DAYS]
WHERE [DATE] = CAST(GETDATE() AS DATE)
),
pd AS (SELECT [DATE] AS REPORTING_PERIOD
FROM dbo.Bz_DAYS
WHERE DAY([DATE]) = 1
)
SELECT sp.*,
rp.REPORTING_PERIOD,
ac.DATE_ORDINAL AS CUSTOMER_ACCEPTANCE_ORDINAL,
mv.DATE_ORDINAL AS CUSTOMER_MOVE_ORDINAL,
today.DATE_ORDINAL TODAY_ORDINAL
/*sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED], sp.[LEASE_SIGNED_BY_GSA],
sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE],
COALESCE(sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED], sp.[LEASE_SIGNED_BY_GSA],
sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE]
) AS REPORT_MONTH
*/
FROM dbo.Bzo_Den sp
The error is :
Column names in each view or function must be unique. Column name
'CUSTOMER_MOVE' in view or function 'VW_Bzo_D' is specified more than
once.
I dont know if this will help but did you try aliasing the column names which is giving you trouble?
One of the other users had a similar problem and he tried aliasing. Please look at the link below
Create view in sql server "names in each view or function must be unique"
Hope it helps.
Hi I am trying to migrate an access database into postgresql and everything was going well until i tried this view. I am wanting it to create a new column called 'CalculatedHours'. And as Im new to postgresql I am slightly confused. Heres the code that I keep putting into pgAdmin and getting the error...
SELECT "SessionsWithEnrolmentAndGroups"."SessionID",
"Assignments"."Staff",
"SessionsWithEnrolmentAndGroups"."groups",
"SessionsWithEnrolmentAndGroups"."SessionQty",
"SessionsWithEnrolmentAndGroups"."Hours",
"SessionsWithEnrolmentAndGroups"."Weeks",
"Assignments"."Percentage",
"Assignments"."AdditionalHours",
Round((coalesce(("groups"),1)*("SessionQty")*("Hours")*("Weeks")
*("Percentage"))) AS CalculatedHours,
(CalculatedHours)+coalesce(("AdditionalHours"),0) AS "TotalHours"
FROM "SessionsWithEnrolmentAndGroups"
INNER JOIN "Assignments"
ON "SessionsWithEnrolmentAndGroups"."SessionID" = "Assignments"."SessionID";
You cannot access column aliases in the same select where they are defined. I would suggest a subquery:
SELECT t.*,
(CalculatedHours)+coalesce(("AdditionalHours"), 0) AS "TotalHours"
FROM (SELECT eag."SessionID", a, eag."groups", eag."SessionQty",
eag."Hours", eag."Weeks", a."Percentage", a."AdditionalHours",
Round((coalesce(("groups"),1)*("SessionQty")*("Hours")*("Weeks")*("Percentage"))) AS CalculatedHours
FROM "SessionsWithEnrolmentAndGroups" eag INNER JOIN
"Assignments" a
ON eag."SessionID" = a."SessionID"
) t;
Your queries would also be much more readable using table aliases and getting rid of the escape characters (double quotes) unless they are really, really needed.