Is it possible to generate any chart for example line chart that plots on Y axis a function of X where X is not expressed in time but any other unit?
let say you have
f(x) = 2x +1
and would like to plot it for a data range between 1 and 3 so:
x = 1; y = 3;
x = 2; y = 5;
x = 3; y = 7;
If it is possible then how to crate such chart, perfectly working with MySQL DB where in one column you have X, and other column is Y?
I have such example test table (MySQL), X is X axis, Y is value (Y axis) Z is series of data:
+---+---+------+
| x | y | z |
+---+---+------+
| 1 | 3 | 1 |
| 2 | 5 | 1 |
| 3 | 7 | 1 |
+---+---+------+
how to write a simplest Grafana MySQL query so it shows data with Plotly?
Stacked bar charts not based on time = huge advantage for Grafana if they can ever figure it out. Until then I will stick it out with Kibana.
Related
I know that this is more of a Math problem, but I am not certaint as to how to perform math correctly in a query anyways. What Im trying to do, is get a column from a database, where a point (x, y) is inside a region saved in another column of that row (x, y) - (x + 16, y + 16).
The database loks something like:
+--------+---------------+
| Name | Position |
+--------+---------------+
|Area1 |16:32 |
|Area2 |-32:16 |
|Area3 |128:64 |
+--------+---------------+
An area is the saved cordinates (X:Y) + 16. It's basically a grid of 16x16 areas.
I'm trying to get the name of the area by the position of a point (x, y), which can be anywhere in that area.
If this would make things easier, It is possible to change the "Position" column to 2 diffent one aka something like:
+--------+---------------+---------------+
| Name | Position_x | Position_Y |
+--------+---------------+---------------+
|Area1 |16 |32 |
|Area2 |-32 |16 |
+--------+---------------+---------------+
Thanks in advance!
If I understand you correctly, you just need to check that the x value is between Position_x and Position_x+15 (inclusive) and the same for y:
SELECT *
FROM areas
WHERE 20 BETWEEN Position_x AND Position_x + 15
AND 40 BETWEEN Position_y AND Position_y + 15
Output (for your sample data):
Name Position_x Position_Y
Area1 16 32
Demo on dbfiddle
I have multiple data sets like this
data set 1
index| name | val|
1 | a | 1 |
2 | b | 0 |
3 | c | 3 |
data set 2
index| name | val|
1 | g | 4 |
2 | a | 2 |
3 | k | 3 |
4 | l | 2 |
I want to combine these data sets in such a way that if the both the data sets have a row with a common element name, in this example, "a", i want to have only a single row for the combined dataset, where the value is sum of that a and this a, in this case the combined row a would have a val of 3 (2+1). index number for elements does not matter. is there an effective way to do this in excel itself? I'm new to querying data, but im trying to learn. If i can do this in pandas(i'm trying to make myself familiar in this language) or sql, I will do so. My data sets are of different sizes
use:
df3 = df1.groupby('name').sum().add(df2.groupby('name').sum(), fill_value=0).reset_index()
df3['val'] = df3.fillna(0)[' val']+df3.fillna(0)['val']
df3 = df3.drop([' val'], axis=1)
print(df3)
Output:
name index val
0 a 3.0 3.0
1 b 2.0 0.0
2 c 3.0 3.0
3 g 1.0 4.0
4 k 3.0 3.0
5 l 4.0 2.0
IN Sql you can try below query:
select name,sum(val)
from
(select index,name,val from dataset1
union all
select index,name,val from dataset2) tmp
group by name
In Pandas:
df3=pd.concat([df1,df2],ignore_index=True)
df3.groupby(['name']).sum()
I have a linked MySQL -server to MSSQL-server and I am trying to INSERT data to the table admin_user on the MySQL -server, but end up getting the error:
Cannot process the object "dbo.admin_user". The OLE DB provider
"MSDASQL" for linked server "MYDB" indicates that either the object
has no columns or the current user does not have permissions on that
object.
This works fine:
SELECT * FROM openquery([MYDB], 'SELECT * FROM admin_user')
This gets the error:
INSERT into openquery([MYDB], 'dbo.admin_user') values ('Testi','Testaaja','me#google.com','koe','','','','','','1','N;','','')
Here are the rights of the user whom I used for creating the ODBC-connection
| xx.xxx.xxx.xx | me | *qweqweqwdq2edqdadasd|
Y | Y | Y | Y | Y |
Y | Y | Y | Y | Y | N
| Y | Y | Y | Y | Y
| Y | Y | Y | Y
| Y | Y | Y | Y
| Y | Y | Y | Y |
Y | | | |
| 0 | 0 | 0 | 0
| | NULL |
> | % | me | *asdasadasdsadasdasdsad| Y | Y | Y | Y | Y |
> Y | Y | Y | Y | Y | Y
> | Y | Y | Y | Y | Y
> | Y | Y | Y | Y
> | Y | Y | Y | Y
> | Y | Y | Y | Y |
> Y | | | |
> | 0 | 0 | 0 | 0
> | | NULL |
My catalog is bitnami_magento, I have the provider string configured with
DRIVER=(MySQL ODBC 5.3 ANSI Driver); SERVER=
XX.XXX.XXX.XXX;PORT=3306;DATABASE=bitnami_magento;
USER=me;PASSWORD=mypass;OPTION=3;
Also I have unchecked the "Level zero only" box from Provider Options (MSDASQL) and made sure that ad_hoc queries are allowed. What I am doing wrong?
There are the instructions that I followed
http://dbperf.wordpress.com/2010/07/22/link-mysql-to-ms-sql-server2008/
You have an error in your query:
In the OPENQUERY() you have to use the MySQL table name instead of the MSSQL one (if you want to insert into the MySQL table).
The following syntax should work
INSERT INTO OPENQUERY([MYDB], 'SELECT * FROM mysqlDbName.mysqlTableName') VALUES
('Testi','Testaaja','me#google.com','koe','','','','','','1','N;','','')
Please change the mysqlDbName.mysqlTableName to you MySQL database and table name accordingly.
The problem was I am an idiot. The syntax for Openquery expects a result set to be returned.
So it apparently needs a "dummy query" to be incorporated as a part of the actual query so it will get the result set in response. Writing "where 1=0" makes the query faster as it will not get any actual results in response.
Working example:
insert openquery(MYDB, 'select firstname from admin_user where 1=0') values ('3','Testi','Testaaja','me#google.com','koe12','koe22','','','','0','0','1','','','')
OpenQuery requires a result set to be returned, but UPDATE, DELETE,
and INSERT statements that are used with OpenQuery do not return a
result set.
http://support.microsoft.com/kb/270119/fi
I'd like to make a database of products. Each product have characteristics described as an array of x values and corresponding y values.
And I'd like to query products for certain characteristics.
Example product data:
ProductA_x = [10, 20, 30, 40, 50]
ProductA_y = [2, 10, 30, 43, 49]
ProductB_x = [11, 22, 33, 44, 55, 66]
ProductB_y = [13, 20, 42, 35, 28, 21]
Now I'd like to get a list of products where y < 35 # x=31.
In the example data case, I should get ProductA.
If I use MySQL, what would be a good way to define table(s) to
achieve this query at SQL level?
Would it become easier if I could use PostgreSQL? (Use
Array or JSON type??)
One way I was advised was to make a table to specify xy pairs for x range. First data is for range x[0] to x[1], next data is for x[1] to x[2]. Something like this.
| ProductID | x1 | x2 | y1 | y2 |
| --------- | -- | -- | -- | -- |
| 1 | 10 | 20 | 2 | 10 |
| 1 | 20 | 30 | 10 | 30 |
| 1 | 30 | 40 | 30 | 43 |
| 1 | 40 | 50 | 43 | 49 |
| 2 | 11 | 22 | 33 | 44 |
| 2 | 22 | 33 | 20 | 42 |
| 2 | 33 | 44 | 42 | 35 |
| 2 | 44 | 55 | 35 | 28 |
| 2 | 55 | 66 | 28 | 21 |
Then I could query for (x1 > 31 AND 31 < x2) AND (y1 < 35 OR y2 < 35)
This solution is not too bad but I wonder if there is cleverer approach.
Please note that x array is guaranteed to be incremental but different product would have different starting x value, step size and number of points. And x value to be searched for may not exist as exact value in x array.
The length of real x and y arrays would be about 2000. I expect I'd have about 10,000 products.
It would be best if corresponding y value can be interpolated but searching y value at nearest x value is acceptable.
since every X corresponds to exactly one Y, the sane table definition on a classic relational database would be:
CREATE TABLE product (id serial not null unique, sku text primary key, ....);
CREATE TABLE product_xy (product_id int not null references product(id),
x int not null,
y int not null,
primary key(product_id, x));
That would make your query manageable in all cases.
On PostgreSQL 9.3 you could use a LATERAL subquery to effectively use arrays but I don't think it would be easier than just going with a relational design to start with. The only case where you would want to store the info in an array in PostgreSQL is if ordinality mattered on the x array. Then the design becomes slightly more complex because the following array combinations are not semantically the same:
array[1, 2, 3] x
array[4, 5, 6] y
and
array[2, 1, 3] x
array[5, 4, 6] y
If those need to be distinct then go with an array-based solution in PostgreSQL (note that in both cases the same x value corresponds with the same y value, but the ordering of the pairs differs). Otherwise go with a standard relational design. If you have to go with that, then your better option is to have a 2-dimensional xy array that would be something like:
array[
array[1, 2, 3],
array[4, 5, 6]
] xy
You could then have functions which could process these pairs on the array as a whole, but the point is that in this case the xy represents a single atomic value in a specific domain, where ordinality matters in both dimensions and therefore the value can be processed at once. In other words, if ordinality matters on both dimensions, then you have a single value in your domain and so this does not violate first normal form. If ordinality along either dimension does not matter, then it does violate first normal form.
We are using a programming language that does not have a linear regression function in it. We have already implemented a single variable linear equation:
y = Ax + B
and have simply calculated the A and B coefficents from the data using a solution similar to this Stack Overflow answer.
I know this problem gets geometrically harder as variables are added, but for our purposes, we only need to add one more:
z = Ax + By + C
Does anyone have the closed form equations, or code in any language that can solve for A, B and C given an array of x, y, and z's?
so you have three linear equations
k = aX1 + bY1 + cZ1
k = aX2 + bY2 + cZ2
k = aX3 + bY3 + cZ3
What you can do is rewrite it as matriz
| x1 y1 z1 | | a | | k |
| x2 y2 z2 | | b | = | k |
| x3 y3 y3 | | c | | k |
to work out [a b c ] do the following matrix operation
| a | | x1 y1 z1 | | k |
| b | = inverse( | x2 y2 z2 | ) | k |
| c | | x3 y3 y3 | | k |
The formula for a 3x3 matrix inverse can be found here
Yes, it's an easy linear algebra problem if you think of it the way Gil Strang does it. Here's a written explanation.
Can you use MatLab or does the calculation have to occur inside your software?
MatLab instructions on multiple regression analysis.
Integrating MatLab with C#.