Can I query 285 IDs and URLs in a single elegantly formed SQL query - mysql

I have to query 285 IDs and paths. At first glance, there are no real patterns to the ID's and I'm not certain there's a way to achieve this end with a simple and elegant query.
However, I'm by no means an expert and still learning SQL. So, hoping for some guidance.
Below is an extract of the first 50 enttries i'm trying to match:
ID path
261617 /About/Factfile
31 /About/Factfile/18060
761 /About/Factfile/18060/11550
762 /About/Factfile/18060/11552
763 /About/Factfile/18060/11555
35 /About/Factfile/scotlandsnapshot
63 /About/Government/background
74 /About/Government/sgprevious
1555 /About/Government/sgprevious/2007-2011
328782 /About/Government/sgprevious/2011-2016
1553 /About/Government/sgprevious/sgprevious1999-2003
1554 /About/Government/sgprevious/sgprevious2003-2007
46 /About/Information/expenditure
271169 /About/Information/expenditure/GPC
329992 /About/Information/expenditure/GPC/epc500-16-17
297247 /About/Information/expenditure/GPC/GPC
297249 /About/Information/expenditure/GPC/GPC/GPC
297243 /About/Information/expenditure/GPC/GPC500
271168 /About/Information/expenditure/over-25k
1550 /About/Information/expenditure/over-25k/background
1551 /About/Information/expenditure/over-25k/reports
22138 /About/Information/expenditure/over-25k/reports/2011-2012
291275 /About/Information/expenditure/over-25k/reports/expenditure
22137 /About/Information/expenditure/over-25k/reports/Expenditure2010
266779 /About/Information/expenditure/over-25k/reports/reports
303729 /About/Information/expenditure/over-25k/reports/Test
316271 /About/Information/expenditure/over-25k/reports/Test1
276826 /About/Information/expenditure/PSRA2010
293815 /About/Information/expenditure/PSRA2010/2011-12-PSRduties
318093 /About/Information/expenditure/PSRA2010/duties-13-14
311621 /About/Information/expenditure/PSRA2010/duties-2012-13
294347 /About/Information/expenditure/PSRA2010/historic-efficiency-reports
276831 /About/Information/expenditure/PSRA2010/historicexpenditure10-11and11-12
261611 /About/People
23769 /About/People/14944/Events-Engagements/MinisterialEngagements
148038 /About/People/14944/Events-Engagements/MinisterialEngagements/2008
148037 /About/People/14944/Events-Engagements/MinisterialEngagements/2009
148036 /About/People/14944/Events-Engagements/MinisterialEngagements/2010
148039 /About/People/14944/Events-Engagements/MinisterialEngagements/201112
268177 /About/People/14944/Events-Engagements/MinisterialEngagements/2012-13
296737 /About/People/14944/Events-Engagements/MinisterialEngagements/2013-14Engagements
304646 /About/People/14944/Events-Engagements/MinisterialEngagements/2014-15Engagements
317634 /About/People/14944/Events-Engagements/MinisterialEngagements/MinisterialEngagements
987 /About/People/14944/Special-Advisers
254426 /About/People/14944/Special-Advisers/gifts-hospitality
1048 /About/People/14944/travel
23479 /About/People/14944/travel/airtravel
23481 /About/People/14944/travel/ferrytravel
23483 /About/People/14944/travel/MinisterialCarJourneys
148029 /About/People/14944/travel/MinisterialCarJourneys/2010-11
Should this be split into 2 queries, 1 for the ID's and another for the paths?
Thank you all in advance and please forgive me if this is n00b stuff.
Kind regards,
V

SELECT id, path
FROM tbl
ORDER BY path
LIMIT 285;

Related

combining similar records to a single record in MS Access

I'm working MS Access 2016, on a table that has student results: So the fields are simply studentID, Test, and Score. For reporting purposes, I need to generate a CSV file that has a student's TestScore values all in one row. So if I had:
StudentID: Test: TestScore:
A123 TestA 80
A123 TestB 90
B123 TestA 70
B123 TestB 95
How do I generate a table for export that looks like:
StudentID: TestA: TestB:
A123 80 90
B123 70 95
I don't think crosstabs would work because not all students in the table have taken all the same tests. And there are several thousand cases. I also have come to understand that may not be possible via SQL in MS Access.
Many thanks in advance for any helpful advice.
You can add the ColumnHeadings property of the Crosstab Query, include all tests - "TestA";"TestB";...
Are there only a set number or could this grow?
So thank you to Andre and Alex for guiding me to this solution, which works for the original question:
Table name here is "Output".
TRANSFORM Last(Output.[TestScore]) AS LastOfTestScore
SELECT Output.[StudentID]
FROM [Output]
GROUP BY Output.[StudentID]
PIVOT Output.[Test];
For someone else searching for a similar solution, note that I used "Last" instead of something else (you might want First, Count, etc.).

5 point average in SSRS

I try to put a 5 point avg in my chart. I add a trendline, but it looks like this:
And then I created a new series to calculate there the avg. and this looks like this:
but I would like to show this in a 5 point average. How can I do this?
This answer is based on my experience with Excel, not reporting services, but it is probably the same problem.
Your chart is probably a scatter plot rather than a line chart (note: this is Excel terminology). A scatter plot does not have an intrinsic ordering in the data. A line chart does.
The solution (for a scatter plot) is simply to sort the data by the x-values. The same will probably work for you. If you are pulling the data from a database, then order by can accomplish this. Otherwise, you can sort the data in the application.
Using this post as a starting point you can see that it is possible to calculate a moving average for a chart using the SQL query that pulls the data from the database.
For example, using this table in my database called mySalesTable
myDate sales myDate sales myDate sales
---------- ------ ---------- ------ ---------- ------
01/01/2015 456 16/01/2015 546 31/01/2015 658
02/01/2015 487 17/01/2015 12 01/02/2015 121
03/01/2015 245 18/01/2015 62 02/02/2015 654
04/01/2015 812 19/01/2015 516 03/02/2015 261
05/01/2015 333 20/01/2015 1 04/02/2015 892
06/01/2015 449 21/01/2015 65 05/02/2015 982
07/01/2015 827 22/01/2015 15 06/02/2015 218
08/01/2015 569 23/01/2015 656 07/02/2015 212
09/01/2015 538 24/01/2015 25 08/02/2015 312
10/01/2015 455 25/01/2015 549 09/02/2015 21
11/01/2015 458 26/01/2015 261
12/01/2015 542 27/01/2015 21
13/01/2015 549 28/01/2015 21
14/01/2015 432 29/01/2015 61
15/01/2015 685 30/01/2015 321
You can pull out this data, and create a Moving average based on the last 5 dates by using the following query for your dataset
SELECT mst.myDate, mst.sales, avg(mst_past.sales) AS moving_average
FROM mySalesTable mst
JOIN mySalesTable as mst_past
ON mst_past.myDate
BETWEEN DATEADD(D, -4, mst.myDate) AND mst.myDate
GROUP BY mst.myDate, mst.sales
ORDER BY mst.myDate ASC
This is effectively joining a sub-table for each row consisting of the previous 4 dates and the current date, and finds the average for these dates, outputting that as the column moving_average
You can then chart both these fields as normal, to give the following output (with the data table so you and see the actual calculated moving average)
Hopefully this will help you. Please let me know if you require further assistance

MySQL query involving complicated summing function

I don't know how to put my requirement in words but let me explain it with a table and output that I desire
The table looks like this
Package LanguageUsed UnitsSold
lmn basic 43
xyz pascal 20
abc basic 50
cba c 20
Output I want is
LanguageUsed UnitsSold
basic 93 43+50
pascal 20 20+ nothing
c 20 20+ nothing
I need to display number of packages sold in each language
How can I do this in MySQL?
I need to display number of packages sold in each language
You can do:
SELECT languageUsed, SUM(UnitsSold)
FROM yourTABLE
GROUP BY languageUsed

Converting data from matrix to vector format

I have huge set of data in an excel file in the following format
School_id percentage year subject
1100 90 2005 maths
1100 95 2006 maths
1100 81 2005 science
2310 45 2007 biology
I want to convert this data to this format
School_id year maths science biology
1100 2005 90 81
1100 2006 95
23100 2007 45
I dont have any idea for how to do this conversion. Will this be possible with excel or mysql or any other tool? Need some suggestions.
Thanks in advance
Yea so like they said pivot tables. To get your results, I had to do it using CONCATENATE function. There might be a better way. But this is how I did it:
first do a CONCATENATE column:
Then insert your pivot table and select the right options:
Then de-concatenate your School_id and Year
Like I said there might be a better way to do this - but then you would just need to organize your headers the way you want them and you should have what you are looking for. Good Luck.

What would be the best practice to store multiple 2 digit dataset in MySql server

Let say i want to store several dataset ie
78 94 33 22 14 55 18 10 11
44 59 69 79 39 49 29 19 39
And later on i would like to be able run queries that will determine the frequency of certain number. What would be the best way to this? What would be table structure to make a fast query.
Please be specific as you can be.
To get the counts, you can run a query such as:
SELECT value, COUNT(*) from table_of_values GROUP BY value
Placing an index on the single integer value column is pretty much all you can do to speed that up.
You could of course also just keep a table with every two-digit value and a count. You will have to pre-fill the table with zero counts for every value.
Then increment the count instead of inserting:
UPDATE table_of_values SET count = count + 1 WHERE value = (whatever)