I am trying to get some municipalities and their population (P1082) over the years using SPARQL in Wikidata. The query I am using works, but I do not know how to convert the years of the population figures into columns, so that I only have a single unique item. The structure I would want to be returned in the query is:
place placeLabel 1815 1830 1840 ... 2019 2020 parentPlaceLabel
wd:Q9908 Bloemendaal 1458 1748 2058 ... 23410 Q101626200
wd:Q9928 Heemstede 2186 2227 2332 ... 27286 27234 Q101626200
I have been reading about BIND but find it difficult to adapt it to the code since the code I am using gets all the population point in time (P585) qualifier values.
Related
I can't resolve this issue. I tried to use PIVOT() function, I've read the documentation and tried to use that. Additionally, I tried to find the answer but didn't find.
The main problem is using PIVOT() function, that it has to include aggregation function, but I needn't it, I need only pivot the table without any aggregation.
The source table:
COUNTRY
LEVEL
NUMBER
Germany
High
22
Germany
Medium
5
Germany
Low
3
Italy
High
43
Italy
Medium
21
Italy
Low
8
Canada
High
9
Canada
Medium
3
Canada
Low
13
I'd like to get the output table looks like:
COUNTRY
High
Medium
Low
Germany
22
5
3
Italy
43
21
8
Canada
9
3
13
Can anybody help me?
How to do that without using aggregation function or using but the get all values. Cause, for example, if I use min() or max() I get the max and min value and the others cells would be empty.
why do you think that using min/max would leave empty cells? As there is only one value for each country/level combination then using min or max is effectively just picking that one value.
Obviously, if your source data had more than one record for each combination of country/level then you'd need to decide how to deal with it.
This SQL seems to work fine:
select *
from COUNTRY_INFO
pivot(max(NUMBER) for LEVEL in ('High', 'Medium', 'Low'))
as p
order by country;
Given this Query
TRANSFORM Count(books.ID) AS CountOfID
SELECT books.Category
FROM books
WHERE (((books.Category)='Fantasy'))
GROUP BY books.Category
PIVOT (Switch(books.status=1,'Available',books.status=2,'Reserved',books.status=3,'Unavailable'));
that gives this result:
Category Total Available Unavailable
Fantasy 116 46 70
I am trying to display it on a Pie Chart which, somehow shows the portion per status together with its value, look like this:
but instead, I am getting this result:
I don't know where the East, West, and North are coming from. Another thing I observed is in the Row Source property why it becomes like this:
SELECT [Unavailable],Sum([Available]) AS [SumOfAvailable] FROM [qryGetFantasy] GROUP BY [Unavailable];
I am using Office 2013.
Any help is much appreciated.
So I am trying to create a view that allows the user (from the front-end) query on it by specifying a specific date (in the form of a varchar/string). The view/query will then return data for the month of the specified date and also data for 13 months prior to it. When I run the following query and enter a valid 'string'/date , I am able to return results successfully. However, when I try to create a view with the same query, i am receiving the following error:
SQL Error: ORA-01027: bind variables not allowed for data definition operations
Below is the query:
SELECT person_name
, person_age
, person_dob
FROM person p
WHERE p.person_dob >= add_months(to_date(:par_date, 'yyyy-mm-dd'), -13);
Here is some sample data:
Person_Name Person_Age Person_DOB
Jon 18 01-01-1990
Jacob 21 09-04-1994
Heidi 28 04-02-2010
mark 30 05-02-2011
Helga 18 03-02-2015
Mike 18 01-02-1992
Larry 18 01-04-1993
I want to return the following result after specify :par_date as '2020-03-02'.
Person_Name Person_Age Person_DOB
Heidi 28 04-02-2010
mark 30 05-02-2011
Helga 18 03-02-2015
You unfortunately cannot do this. The closest you could come would be to create a table function, but that will be much less efficient than just selecting from the table with a 'WHERE' clause.
Ask Tom has a work around, but it is complex, much more work, and potentially very inneficient. Just use a 'WHERE' clause on the view or table
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9536277800346269502
I have a linked table in Access that I want to update from a local table. The problem is that the linked table is used for specifications so it contains one line for each attribute. For example, the two fields used in the linked table are ATTRIBUTE_DESC and ATTRIBUTE_VALUE. Each specification may have multiple descriptions. Here is a sample from the linked table:
SPECIFICATION_NO SPEC_SEQ_NO ATTRIBUTE_DESC ATTRIBUTE_VALUE
------------------ ----------- --------------- -----------------
0000000001 10 MANUFACTURER AMERICAN DARLING
0000000001 15 MODEL B84B-5
0000000001 20 YEAR MANUFACTURED 2000
0000000001 25 DATE INSTALLED 5/3/1999
0000000001 30 EXTENSION LENGTH
0000000001 35 MAIN VALVE SIZE 6
0000000001 40 ISOLATION VALVE DIAMETER
0000000001 45 ISOLATION VALVE DIRECTION
0000000001 50 ISOLATION VALVE DISTANCE
0000000001 55 AS BUILT # C025-106-113
0000000001 60 ENVIRONMENT
0000000001 65 STR
0000000001 70 FIVE YEAR PM DUE OCTOBER 2015
The local table has different ATTRIBUTE_VALUES based on the ATTRIBUTE_DESC in the linked table. For example, above the MANUFACTURER might be CLOW instead of AMERICAN DARLING.
The query I created has all of the relevant specification information in the table and I've used the ATTRIBUTE_DESC with different criteria to update the ATTRIBUTE_VALUE.
Unfortunately doing it this way I get an error "Duplicate Output Destination "PROD_SA_SPECIFICATION_DETAILS.ATTRIBUTE_VALUE". So my question is whether there is a better way to update this type of table - either through a different query setup or via VBA. I don't know much VBA so if that is the best answer can I get an example for one of the attributes?
Thanks.
My query is like this:
Table being updated: PROD_SA_SPECIFICATION_DETAILS
Field: ATTRIBUTE_VALUE
Table: PROD_SA_SPECIFICATION_DETAILS
Update to: [UPDATE: SA_SPECIFICATION_DETAILS].[ATTRIBUTE_VALUE]
Criteria: MANUFACTURER
So I have the same for each criteria, none of the criteria are duplicated. In the case above there would be 13 as above with the different criteria. I realize I could use the sequence number since they are different for each spec but we add lines and remove lines on occasion and I'd rather not have to remember to update the query so that wrong information goes in the wrong fields.
I realize that this table is not normalized and that is by design (blame Oracle). It is not normalized because various specifications may be variable lengths, ie some may have 10 lines and some may have 12. There are two parts to this table the other is the SA_SPECIFICATION_DATA which is linked by specification_no.
My Questions:
Is there a way to add quotes around %{macro_name} in my SQL query ?
Is there a better way to create the required report (i.e. not using RapidMiner)?
My Process:
I'm currently trying to create a custom report of data stored in a MySQL database. Here is an hypothetical example of my table data:
Item_Name Item_Price Item_Stock Item_Timestamp
Dish Soap 3.99 25 1/1/2013 12:00am
Frogs 0.69 26 1/1/2013 12:00am
Frogs 0.69 19 1/1/2013 1:00am
Dish Soap 3.99 28 1/1/2013 1:00am
Item_Timestamp refers to the datetime of when the entry was made.
I'm attempting to use RapidMiner to do the following:
Provide a summation of increases in Item_Stock for each unique Item_Name
Provide a summation of decreases in Item_Stock for each unique Item_Name
Provide the average rate of change over a specified time period
My goal is to create a report that tells me whether items are being restocked at a rate of equilibrium with demand.
In order to create a report for each unique Item_Name, I have created a RapidMiner process which loads unique Item_Name as an example set, then attempts to loop through the exampleset by using the extract macro operator which sends the Item_Name from each example to another SQL query. RapidMiner uses %{macro_name} as the syntax for the macro. My SQL query looks like:
Select Item_Name
From thisTable
Where Item_Name = %{macro_name}
The problem is that this query throws an exception, but I'm not sure why. Perhaps the problem is that %{macro_name} returns a string without the necessary quotes, but I am unsure.
My questions are:
Is there a way to add quotes around %{macro_name} in my SQL query ?
Is there a better way to create the required report (i.e. not using RapidMiner)?
I figured out the main problem:
My current SQL string has a syntax problems. I needed to capitalize and there should be no space before %{macro_name}
SELECT Item_Name
FROM `thisTable`
WHERE Item_Name =%{macro_name}