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
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 have 2 tables : dt_user and dt_invoice.
**dt_members :**
id firstname
3 Salim
5 Sara
8 Julie
**dt_invoice**
user_id amount_ht period month year
3 4950 04 2018 04 2018
3 7200 10 2018 10 2018
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
3 8800 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
3 7550 03 2019 03 2019
I want to create a query joining the two table, but i want to show each user_id for PERIOD that there is in table dt_invoice.
**Expected results :**
user_id amount_ht period month year
3 4950 04 2018 04 2018
5 0 04 2018 04 2018 //non-existent record in dt_invoice
8 0 04 2018 04 2018 //non-existent record in dt_invoice
3 7200 10 2018 10 2018
5 0 10 2018 10 2018 //non-existent record in dt_invoice
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
5 0 11 2018 11 2018 //etc ...
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
5 0 12 2018 12 2018
8 0 12 2018 12 2018
3 8800 01 2019 01 2019
5 0 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
5 0 02 2019 02 2018
8 0 02 2019 02 2018
3 7550 03 2019 03 2019
5 0 03 2019 03 2018
8 0 03 2019 03 2018
Thanks in advance for your help, i'm totally stuck ..
SQL datas available here : https://rextester.com/live/LBSEY76360
also in sqlfiddle : http://sqlfiddle.com/#!9/728af3/1
Use a cross join to generate the rows and left join to bring in the values:
select m.user_id, p.period, p.month, p.year,
coalesce(t.amount_ht, 0) as amount_ht
from dt_members m cross join
(select distinct period, month, year from dt_invoice) p left join
dt_invoice t
on t.user_id = m.id and t.period = p.period;
Maybe this would help.
SELECT user_id, amount_ht, period, month, year
FROM dt_invoice
LEFT JOIN dt_members ON user_id = id
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
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