I have data organized in this way:
country1 country2 year ally
USA USSR 1990 0
USA UK 1990 1
UK USSR 1990 0
USA USSR 1992 0
USA UK 1992 1
UK USSR 1992 1
What I want to do is to have another vector that contains the similarity scores for each pair of countries per year. Is there any easy way to do this in iGraph? Thanks.
Related
Working on SSRS. Have the following data set.
ID City Country
1 London England
2 Glasgow Scotland
3 Aberdeen Scotland
4 Swansea Wales
5 London England
6 Glasgow Scotland
7 Glasgow Scotland
8 Manchester England
Would like to have a table, grouped by the city and showing how many occurrences there have been for each city, see below?
City Country Total
Glasgow Scotland 3
London England 2
Manchester England 1
Swansea Wales 1
Aberdeen Scotland 1
How would i go about doing this please?
After creating a group of City use the following expression:
=COUNT(Fields!City.Value,"City")
Let me know if this helps.
It seems from your question that you don't want the detail in the report, only the summary data. If you do want detail, Alejandro Zuleta's answer will work. If you don't need the detail, you can do the grouping in your dataset:
select city, country, count(*) as total
from <yourtable>
group by city, country;
I'm creating a SSRS report and have the following data set.
ID City Country
------------------------------
1 London England
2 Glasgow Scotland
3 Aberdeen Scotland
4 Swansea Wales
5 London England
6 Glasgow Scotland
7 Glasgow Scotland
8 Manchester England
I have a COUNT on the 'City' and grouped by City and Country. This is how I would like it to appear
City Country Total
--------------------------------------------
Glasgow Scotland 3
London England 2
Swansea Wales 1
Aberdeen Scotland 1
Manchester England 1
However, this is how it's appearing
City Country Total
--------------------------------------------
Swansea Wales 1
Glasgow Scotland 3
3
3
Aberdeen Scotland 1
Manchester England 1
London England 2
2
So I need to group by the aggregate total column and also order by that column but not sure how to do it. All help appreciated, thanks.
Have tried Sanjays answer below, unless I'm doing it wrong I'm getting this error.
here
we need to create city and country as group and delete detail section from row groups as like below
so table look like after above changes
and set Count(Fields!ID.Value,"CITY") sd sorting expression for first group city1 with order Z to A
There are multiple ways you could go about this. One option would be to handle the grouping in the query and simply display the results in SSRS. So your query would look something like this:
SELECT ID, City, Country, COUNT(*) as Total
FROM MyTable
GROUP BY ID, City, Country
Now in SSRS you can sort by the Total column since it's not being aggregated in the report.
I'm having difficulties with a query that absolutely has me stumped. I have a mysql database for a restaurant chain that keeps track of menu item prices from year to year. In this particular query I'm trying to obtain only the most recent price for an item at each store.
ItemMenu
pk storeNum itemNum vendorNum size price year
1 5555 2000 3150 Large 3.99 2015
2 5555 2000 3150 Large 3.75 2014
3 3333 2000 3153 Large 3.69 2014
4 2222 2000 3150 Large 3.89 2014
5 2222 2000 3150 Large 3.69 2013
ItemList
itemNum item categoryNum
2000 Mashed Potatoes 2000
2001 Green Beans 2000
2002 Coleslaw 2000
2003 Baked Beans 2000
2004 Corn 2000
ItemCategory
categoryNum type
2000 Side
2001 Dessert
2002 Drink
2003 Sauce
ItemVendor
vendorNum vendorName
3150 Acme Foods
3152 John's Vegetables
3153 Smith's Wholesale
Stores
storeNum franchisee address phone
5555 David Smith 9999 Main st 555-1212
3333 James Bond 123 Baker 867-5309
2222 Mark Jones 450 21st Ave 888-5411
What I would like to have returned is
storeNum, franchisee, item, type, vendorName, size, price, year
But only for the most recent year.
5555, David Smith, Mashed Potatoes, Side, Acme Foods, Large, 3.99, 2015
3333, James Bond, Mashed Potatoes, Side, Smith's Wholesale, 3.69, 2014
2222, Mark Jones, Mashed Potatoes, Side, Acme Foods, Large, 3.89, 2014
I hope that made sense, I'm at a complete loss of how to join the multiple tables and only pulling data for the most recent year.
Thanks,
Kevin
I have this working but have run into another issue where I may have multiple prices for a given year due to a mid-year price increase. How can I go about adding an additional sub-query to grab the max price after I've selected the max year?
My current query
SELECT m.storeNum, m.itemNum,size,m.price,year FROM ItemMenu m,
(SELECT storeNum, itemNum, MAX(year) maxYear FROM ItemMenu
GROUP BY storeNum, itemNum) yt, (SELECT storeNum, itemNum, MAX(price)
maxPrice FROM ItemMenu) mp
WHERE m.storeNum=yt.storeNum AND m.itemNum=yt.itemNum
AND m.year=yt.maxYear AND m.itemNum=5000 AND m.storeNum=205706;
Returns valid results for max year (I've selected a specific store and item to reduce the number of results).
+----------+---------+------------+-------+------+
| storeNum | itemNum | size | price | year |
+----------+---------+------------+-------+------+
| 205706 | 5000 | Individual | 1.59 | 2014 |
| 205706 | 5000 | Large | 3.69 | 2014 |
| 205706 | 5000 | Large | 3.59 | 2014 |
| 205706 | 5000 | Individual | 1.79 | 2014 |
+----------+---------+------------+-------+------+
I need to further reduce this so I only get the values of $1.79 and 3.69.
Thanks
-Kevin
You'll need to use a subquery: 1st get a set of the most recent year for a given (item,store) pairing. Next, select the price for that (item,store,year) triplet:
SELECT m.storeNum, m.itemNum,price,year FROM ItemMenu m,
(SELECT storeNum, itemNum, MAX(year) maxYear FROM ItemMenu
GROUP BY storeNum, itemNum) yt
WHERE m.storeNum=yt.storeNum AND m.itemNum=yt.itemNum
AND m.year=yt.maxYear;
You can, of course, join the various ID->name tables onto this to get the human-readable data, but I suspect your issue was figuring out how to get the most recent prices.
It should be also noted that this could be done with a JOIN rather than including the subquery in the FROM section; that may be faster.
can anyone please guide me with writing MySQL query for following scenario.
The data in table is like this,
Table Name: user
user_id country city age
----------------------------------------------
1 India Mumbai 22
2 India Mumbai 22
3 India Delhi 22
4 India Delhi 23
5 India Chennai 23
6 China Beijing 20
7 China Beijing 20
8 China Shanghai 20
9 USA New York 30
10 USA New York 30
11 USA New York 30
12 USA Los Angeles 31
13 USA Los Angeles 31
14 USA Los Angeles 40
I want result to be like this which is basically sum of all users in particular country's city having same age.
country city age age_count
----------------------------------------------
India Mumbai 22 2
India Delhi 22 1
India Delhi 23 1
India Chennai 23 1
China Beijing 20 2
China Shanghai 20 1
USA New York 30 3
USA Los Angeles 31 2
USA Los Angeles 40 1
Try this :;
SELECT country,
city,
age,
count(user_id) AS age_count
FROM user
GROUP BY country,
city,
round(age)
select country, city, age, count(*) age_count
from user
group by country, city, age
I have a table of goalie data, snipet below
year gameid player sv% gamenum
2009 200165 John Smith 0.923 0165
2009 209754 John Smith 1.000 9754
2009 206938 John Smith 1.000 6938
2009 206155 John Smith 0.833 6155
2009 203021 John Smith 0.667 3021
2009 206472 John Smith 0.909 6472
2009 209524 John Smith 0.833 9524
2009 209351 John Smith 0.800 9351
2009 203056 John Smith 1.000 3056
2009 206761 John Smith 0.935 6761
2009 200466 John Smith 0.954 0466
2009 204171 John Smith 0.932 4171
2009 207876 John Smith 0.958 7876
2009 201581 John Smith 0.941 1581
2009 205286 John Smith 0.930 5286
2009 208991 John Smith 0.961 8991
2009 202696 John Smith 0.916 2696
2009 206401 John Smith 0.935 6401
2009 200106 John Smith 0.921 0106
2009 201381 John Smith 0.918 1381
I want to get the 10 game moving averages for each goalie, but I don't have dates or game numbers such as his first, second, third game, etc. The game ids are also assigned in the order they are played at the league level, so game 200106 could be his first game of season, and 200165 could be his 2nd, and so on.
My question is: How can I get the max(10 game moving average) and min(10 game moving average) grouped by each goalie for each year?
Also, is there a way to rank the game ids by goalie, year using MySql?
A 10 game moving average means that if you had less than 10 games, there is no meaningful average (not enough games). If you had 12 games, the average is taken between
1-10 (avg)
2-11 (avg)
3-12 (avg)
max / min across the 3 averages
The most efficient way to do this in MySQL would be to
select .. (involving 13 #variables to rownumber and rotate the last
10 values into the variables, keeping track of
#player, #year, #rownumber)
order by player, year, gameid
This will pass through the data only once, building the averages. An outer query will simply take min/max from this derived table. I'm not up for fleshing this out at the moment though.
This is one idea (fair warning:not tested)
SELECT max(mavg) FROM
(SELECT (SELECT avg(avgfield),min(gamenum) as gn FROM YourTable g WHERE g.gamenum>t.gamenum LIMIT 10),t.gamenum
FROM
YourTable t
) d
or
SELECT max(mavg) FROM
(SELECT t.gamenum FROM
YourTable t INNER JOIN
(SELECT avg(avgfield),min(gamenum) as gn FROM YourTable g WHERE g.gamenum>t.gamenum LIMIT 10) q ON q.gn = t.gamenum
) d