How can i calculate Month on Month Growth Calculation in MySQL 5.7. There is no lag function in MySQL 5.7.
My DB contains is as follow
Date State Value
(dd/mm/yy)
1/1/2017 01 25
1/1/2017 02 35
1/2/2017 01 45
1/2/2017 02 58
1/3/2017 01 68
1/3/2017 02 78
I need the output as below
Date State Value MoM
1/3/2017 01 68 XX%
1/2/2017 01 45 XX%
1/1/2017 01 25
1/3/2017 02 78 XX%
1/2/2017 02 58 XX%
1/2/2017 02 35
Thank you
N Rajkumar
Related
I have a table called "ticketManager" in my mssql. There were some expenses missing for "ABC" and I got monthly expenses. I want to divide it equally base on the count of Signed_Date.
Event_ID Name ticket Revenue Expences expect Signed_Date
G-00001 ABC 671 6720 0 50 01 June 2021
G-00002 CSA 5 56 18 100 05 June 2021
G-00003 CSA 5 78 38 100 03 June 2021
G-00004 VSX 23 34 23 NaN 03 June 2021
G-00005 ABC 4 89 0 40 02 June 2021
G-00006 ABC 60 73 0 60 15 April 2021
G-00007 CSA 60 345 110 60 12 June 2021
G-00008 ABC 89 890 NaN NaN 02 June 2021
G-00009 VSX 0 0 0 50 30 April 2021
G-00010 CSA 6 45 16 60 22 June 2021
G-00011 VSX 3 39 23 30 10 June 2021
G-00012 ABC 2 34 0 20 03 June 2021
G-00013 VSX 4 89 48 40 12 June 2021
G-00014 VSX 32 127 35 10 24 April 2021
G-00015 ABC 3 84 0 120 21 April 2021
G-00016 ABC 1 100 0 140 7 June 2021
G-00017 CSA 23 525 90 02 April 2021
for example, in June I have 5 records for ABC and I have expenses as 750.00. So I want to place 150 (750/5) for each record same as for April I have expenses as 110 and have 2 records. So want to place 55 for each record in ABC.
So the table looks like below.
Event_ID Name ticket Revenue Expences expect Signed_Date
G-00001 ABC 671 6720 150 50 01 June 2021
G-00002 CSA 5 56 18 100 05 June 2021
G-00003 CSA 5 78 38 100 03 June 2021
G-00004 VSX 23 34 23 NaN 03 June 2021
G-00005 ABC 4 89 150 40 02 June 2021
G-00006 ABC 60 73 55 60 15 April 2021
G-00007 CSA 60 345 110 60 12 June 2021
G-00008 ABC 89 890 150 NaN 02 June 2021
G-00009 VSX 0 0 0 50 30 April 2021
G-00010 CSA 6 45 16 60 22 June 2021
G-00011 VSX 3 39 23 30 10 June 2021
G-00012 ABC 2 34 150 20 03 June 2021
G-00013 VSX 4 89 48 40 12 June 2021
G-00014 VSX 32 127 35 10 24 April 2021
G-00015 ABC 3 84 55 120 21 April 2021
G-00016 ABC 1 100 150 140 7 June 2021
G-00017 CSA 23 525 90 02 April 2021
I have like million reords like that and have 5 years woth of records. What would be the efficience way to do that?
Thanks in advance.
You can use a window function:
SELECT t.*, avg(Expences) over (partition by extract(year_month from Signed_Date))
FROM ticketManager t;
I am having a data set in the format which i'm attaching below. It contains data for, say, 25 years on a daily basis. I have to take out averages of each column (AA, BB, CC,DD) omitting null values, for a single / multiple months (not all months together) year wise: like avg of AA for the month of Jan and Jul from 90-95. I'm not able to frame a proper query.
NAME DD MM YYYY TIME AA BB CC DD
DLH 01 01 1986 0000 0
DLH 01 01 1986 0100 0
DLH 01 01 1986 0200 0
DLH 01 01 1986 0230 0 6 5 94
DLH 01 01 1986 0300 0
DLH 01 01 1986 0400 0
DLH 01 01 1986 0500 0
DLH 01 01 1986 0530 0 6 5 94
DLH 01 01 1986 0600 0 6
DLH 01 01 1986 0700 0 6
DLH 01 01 1986 0800 0 8
DLH 01 01 1986 0830 0 9 8 95
DLH 01 01 1986 0900 0 9
DLH 01 01 1986 1000 2 14
DLH 01 01 1986 1100 2 17
DLH 01 01 1986 1115 5
DLH 01 01 1986 1130 7 17 9 60
DLH 01 01 1986 1140 7
DLH 01 01 1986 1145 7
DLH 01 01 1986 1150 7
DLH 01 01 1986 1200 8 18
DLH 01 01 1986 1300 6 18
DLH 01 01 1986 1400 10 18
DLH 01 01 1986 1430 7 18 8 50
Assuming I understand your question properly, I would do the following for the example given:
SELECT AVG(x.AA)
FROM
(SELECT AA
FROM Table1
WHERE MM IN (1,7) AND YYYY BETWEEN 1990 AND 1995) x
I have query about following question:
Suppose, we have a 9*7 picture (7 pixels in the x direction and 9 pixels in the y direction), how many warps will have control divergence assuming block of 4*4 threads and 8 threads per warp?
How will the blocks and warps be organized here?
for x or horizontal direction, i can assume 2 blocks per row.Similarly,
for vertical direction, 3 blocks per column.
But, How will the warps are organized? Can someone point out the thread ids of the warps , and the cases where control divergence happens(Thread ids etc for those).
thanks
Suppose, we have a 9*7 picture (7 pixels in the x direction and 9 pixels in the y direction), how many warps will have control divergence assuming block of 4*4 threads and 8 threads per warp?
Divergence is a property of the program (the code), not of the block/warp layout itself. If your algorithm operates identically across all pixels in the image then there will be no divergence whatsoever, irrespective of the number of threads and their organization. If your algorithm branches on warp boundaries, there will be no divergence either. Therefore, without seeing your code, your question is technically unanswerable.
If you're running with a block of 16 threads and 8 threads per warp (which is not physically possible on CUDA hardware: warps are made of 32 threads and their size is not configurable) then you might as well run without a GPU at all. These numbers are way too small to benefit from any hardware acceleration.
How will the blocks and warps be organized here? for x or horizontal direction, i can assume 2 blocks per row.Similarly, for vertical direction, 3 blocks per column. But, How will the warps are organized?
I'll stick to your example and try to provide a schema of the thread IDs, block IDs, warp IDs. Keep in mind that this layout is, in practice, impossible on CUDA hardware.
Image Global Thread IDs Block IDs Local Thread IDs
□□□□□□□ | 00 01 02 03 04 05 06 | 00 00 00 00 00 00 00 | 00 01 02 03 04 05 06
□□□□□□□ | 07 08 09 10 11 12 13 | 00 00 00 00 00 00 00 | 07 08 09 10 11 12 13
□□□□□□□ | 14 15 16 17 18 19 20 | 00 00 01 01 01 01 01 | 14 15 00 01 02 03 04
□□□□□□□ | 21 22 23 24 25 26 27 | 01 01 01 01 01 01 01 | 05 06 07 08 09 10 11
□□□□□□□ | 28 29 30 31 32 33 34 | 01 01 01 01 02 02 02 | 12 13 14 15 00 01 02
□□□□□□□ | 35 36 37 38 39 40 41 | 02 02 02 02 02 02 02 | 03 04 05 06 07 08 09
□□□□□□□ | 42 43 44 45 46 47 48 | 02 02 02 02 02 02 03 | 10 11 12 13 14 15 00
□□□□□□□ | 49 50 51 52 53 54 55 | 03 03 03 03 03 03 03 | 01 02 03 04 05 06 07
□□□□□□□ | 56 57 58 59 60 61 62 | 03 03 03 03 03 03 03 | 08 09 10 11 12 13 14
----------------------------------------------------------------------------
Image Global Warp IDs Block IDs Local Warp IDs
□□□□□□□ | 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00
□□□□□□□ | 00 01 01 01 01 01 01 | 00 00 00 00 00 00 00 | 00 01 01 01 01 01 01
□□□□□□□ | 01 01 02 02 02 02 02 | 00 00 01 01 01 01 01 | 01 01 00 00 00 00 00
□□□□□□□ | 02 02 02 03 03 03 03 | 01 01 01 01 01 01 01 | 00 00 00 01 01 01 01
□□□□□□□ | 03 03 03 03 04 04 04 | 01 01 01 01 02 02 02 | 01 01 01 01 00 00 00
□□□□□□□ | 04 04 04 04 04 05 05 | 02 02 02 02 02 02 02 | 00 00 00 00 00 01 01
□□□□□□□ | 05 05 05 05 05 05 06 | 02 02 02 02 02 02 03 | 01 01 01 01 01 01 00
□□□□□□□ | 06 06 06 06 06 06 06 | 03 03 03 03 03 03 03 | 00 00 00 00 00 00 00
□□□□□□□ | 07 07 07 07 07 07 07 | 03 03 03 03 03 03 03 | 01 01 01 01 01 01 01
----------------------------------------------------------------------------
and the cases where control divergence happens(Thread ids etc for those)
As mentioned above, divergence being a property of the code and not the thread layout, this question cannot be answered without code.
I have two mysql tables
suppose table one name 'marks'
no A B C D
1 10 05 01 04
2 08 07 10 05
3 09 05 07 10
4 07 05 04 10
5 04 07 06 09
6 05 09 07 07
7 09 05 10 06
8 09 06 06 08
9 08 06 10 07
10 08 07 04 06
suppose table two name 'results'
in second table I want to put total marks and average marks based on above table.(import data from 'marks' table,process it and save it in 'results' table)
So once it filled it must be like this.
I want add column A,B,C,D in 'marks' table and put total value in column 'Total' in table 'results' and average by dividing 'Total' column by 4.
no Total Average
1 20 5.00
2 30 7.50
3 31 7.75
4 26 6.50
5 26 6.50
6 28 7.00
7 30 7.50
8 29 7.25
9 31 7.75
10 25 6.25
So how can I fill the 'result' table using mysql query?
Is it possible to do in mysql?
Thank you
Try something like:
INSERT INTO result (no, total, average)
SELECT no, A+B+C+D, (A+B+C+D)/4
FROM marks
We are using a fulltext search to search for the name of a company and all is going well until we have a company with an ampersand in its name, e.g. 'M&S'.
SELECT name FROM company WHERE MATCH (name) against ('M&S' IN BOOLEAN MODE);
This fails to return any results as MySQL is treating the ampersand as a boolean operator. The boolean mode is desired so it can't simply be turned off.
What I'm looking for is a way to escape the ampersand so that MySQL treats it correctly and finds the record.
Ditching fulltext search in favour of LIKEs isn't exactly an option either
Thanks for your help
Seems like & isn't considered a word character in the collation you use for your fulltext search.
so you have to create your own collation (or recompile your MySQL server) where you add & to the list of word characters like i found out in the MySQL docs (
http://dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html) :
If you want to change the set of characters that are considered word
characters, you can do so in several ways, as described in the
following list. After making the modification, you must rebuild the
indexes for each table that contains any FULLTEXT indexes. Suppose
that you want to treat the hyphen character ('-') as a word character.
Use one of these methods:
Modify the MySQL source: In myisam/ftdefs.h, see the true_word_char()
and misc_word_char() macros. Add '-' to one of those macros and
recompile MySQL.
Modify a character set file: This requires no recompilation. The
true_word_char() macro uses a “character type” table to distinguish
letters and numbers from other characters. . You can edit the contents
of the array in one of the character set XML files to
specify that '-' is a “letter.” Then use the given character set for
your FULLTEXT indexes. For information about the array
format, see Section 10.3.1, “Character Definition Arrays”.
Add a new collation for the character set used by the indexed columns,
and alter the columns to use that collation. For general information
about adding collations, see Section 10.4, “Adding a Collation to a
Character Set”. For an example specific to full-text indexing, see
Section 12.9.7, “Adding a Collation for Full-Text Indexing”.
UPDATE: in case you are using latin1 collation, open your XML file which is at mysql/share/charsets/latin1.xml. and find the corresponding character code in a map - in this case you can take the map for lower case or upper case because this doesn't matter for the ampersand symbol:
<lower>
<map>
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 D7 F8 F9 FA FB FC FD FE DF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
</map>
</lower>
the ampersand's unicode is U+0026 and in utf-8 encoding it's 0x26, so search for 26 in the map - which is in the 3rd row, 7th column.
then in the ctype-map change the type of the character from 10 which means punctuation to 01 which means small letter:
<ctype>
<map>
00
20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
48 10 10 10 10 10 01 10 10 10 10 10 10 10 10 10
84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 20
10 00 10 02 10 10 10 10 10 10 01 10 01 00 01 00
00 10 10 10 10 10 10 10 10 10 02 10 02 00 02 01
48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 10 01 01 01 01 01 01 01 02
02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
02 02 02 02 02 02 02 10 02 02 02 02 02 02 02 02
</map>
</ctype>
restart your MySQL server and the corresponding collation is handling & like it was a small letter.
of course it's better to first copy and rename your new collation XML-file and to also copy and paste the corresponding lines in the Index.xml (don't forget to use a new unused id in the XML tags there) and link them to your new collation XML-file so you don't lose your original collation.
you can find the full documentation where i got most of the information from here:
http://dev.mysql.com/doc/refman/5.0/en/full-text-adding-collation.html
Note - For all those working with Mysql 5.7 version use an unused collation id. The mysql article http://dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html is for Mysql 5.5 version. To get maximum collation Id use following Query -
SELECT MAX(ID) FROM INFORMATION_SCHEMA.COLLATIONS;
EDIT: so the & is splitting it into two separate words... since they are 1 letter it is not returning anything. I tested with "Ma&Sa".. my ft_min_word_len = 4... and it didn't return anything so since the length of that string > 4 but its not returning it has to be splitting it into two words... it looks like the suggestion northkildonan made is what you have to do.
So this may or may not be an answer.. but I hope it is helpful for figuring this out.. try this.
first: run this statement -- SHOW VARIABLES LIKE 'ft_min_word_len'; and affirm that the length is actually = 2
if it is i'm not sure how it is any different than a word that is longer than a length of 4
Second: I did this and got results.
SET UP:
I set up a sample table on my localhost database...
create table company(
`id` int,
`name` varchar(55)
);
insert into company
(`id`, `name`)
values
(1, 'oracle'),
(2, 'microsoft'),
(3, 'M&S'),
(4, 'dell');
TESTS:
tested when ft_min_word_len = 4 and obviously it didn't return anything.
SELECT `name` FROM company WHERE MATCH (`name`) against ("M&S" IN BOOLEAN MODE);
I didn't want to try restarting my localhost database to reset the length to 2 (incase I accidentally mess something up because I use it a lot)..
but I got the idea of trying to look for the name of a company that was longer than a length of 4 with the & in it.
MORE SETUP:
insert into company
(`id`, `name`)
values
(5, 'Mary&Sasha');
ANOTHER TEST:
SELECT `name` FROM company WHERE MATCH (`name`) against ("Mary&Sasha" IN BOOLEAN MODE);
this returned http://screencast.com/t/Rx8mh98OUp
I also did this just incase the collation was messing it up but I doubt that was the problem..
COLLATION STUFF:
ALTER TABLE company MODIFY
`name` VARCHAR(55)
CHARACTER SET latin1
COLLATE latin1_german2_ci;
you can also check your tables collation with:
SHOW TABLE STATUS;
hope this is at least some help :)
& is not a special character in mysql therefore you are able to store and search for the expression &
you can test that as followed
SELECT name FROM `testing` WHERE name LIKE '%&%'
also please try somthing like the following to replace the &.
SET #searchstring = 'M&S';
SET #searchstring = REPLACE(#searchstring,'&','&');
SELECT name FROM company WHERE MATCH (name) against (#searchstring IN BOOLEAN MODE);
You may also take a look at regexp.
http://dev.mysql.com/doc/refman/5.1/en/regexp.html
Here the & is used as followed.
mysql> SELECT '&' REGEXP '[[.ampersand.]]';
The following query is also getting you the result
SELECT *
FROM `testing`
WHERE `name` REGEXP CONVERT( _utf8 'M&S'
USING latin1 ) COLLATE latin1_german2_ci
LIMIT 0 , 30
please also read this thread, maybe you can understand it better then me. This is SQL but they seem to have solved the problem
http://forums.asp.net/t/1073707.aspx?Full+text+search+and+sepcial+characters+like+ampersand+
sorry I couldn´t help more