In PARI/GP in function FACTOR the -1 is a bug or means somthing else? - prime-factoring

First run the function b(n):
? b(n) = lcm(vector(n, i, i))/n
After function c(n):
? c(n)=sum(j=1,n,sum(i=1,n,(-1)^(i+j)/(i+j-1)))
Last run d(n):
? d(n)=factor(denominator(c(n))/b(n))~
and test with 202
? d(202)
The result is:
%8 =
[3 7 17 19 31 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293
307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401]
[1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
What indicates the -1 in factoring results?

You try to factor the rational number. Note, type(denominator(c(202))/b(202)) is t_FRAC instead of t_INT because of denominator(c(202))/b(202) = <some big number>/31. So -1 means just -1 power for divisor 31, and no bug is here.

Related

mysql: how to select group by first character and top 5 by counter

my table look like following
id person counter
1 Ona 4946
2 Mayra 15077
3 Claire 496
4 Rita 13929
5 Demond 579
6 Winnifred 13580
7 Green 1734
8 Jacquelyn 19092
9 Aisha 5572
10 Kian 8826
11 Alexandrea 7514
12 Dalton 14151
13 Rossie 18403
14 Carson 19537
15 Mason 2022
16 Emie 2394
17 Jonatan 6655
18 June 5037
19 Jazmyn 10856
20 Mittie 18928
here is the fiddle
i would like to select the top 5 by counter and group by first character, here is the sql that i tried:
SELECT SUBSTR(person,1,1) AS Alpha, person, counter
FROM myTable
GROUP BY SUBSTR(person,1,1)
ORDER BY SUBSTR(person,1,1) ASC, counter DESC;
how to select desired result as following:
alpha person counter
a Arvid 9236
a Aisha 5572
a Alf 4000
a Ahmad 3500
a Alvin 2100
b Brandon 13000
b Ben 8230
b Bonny 7131
b Bella 4120
b Bun 1200
c Connie 9320
c Calvin 8310
c Camalia 6123
c Cimon 3419
c Clay 2515
im using mysql 8.0
You can do:
select *
from (
select *, row_number() over(partition by substr(person, 1, 1)
order by counter desc) as rn
from myTable
) x
where rn <= 5
order by substr(person, 1, 1), rn
Result:
id person counter rn
---- ---------- -------- --
153 Alf 19758 1
283 Alycia 19706 2
260 Abe 19463 3
223 Assunta 18808 4
300 Ari 18031 5
210 Bennie 18309 1
159 Barry 18281 2
128 Beulah 18080 3
314 Benny 16795 4
474 Barry 15789 5
342 Casandra 19656 1
14 Carson 19537 2
67 Chaim 19429 3
280 Colin 18507 4
500 Corbin 18433 5
380 Daphney 19138 1
234 Dejah 18781 2
241 Derrick 18722 3
49 Dasia 18562 4
312 Darrel 17903 5
163 Evalyn 19847 1
79 Ernestine 19523 2
344 Emilie 19520 3
371 Eva 19119 4
469 Emma 18403 5
140 Fiona 19522 1
216 Flo 18314 2
356 Frieda 16082 3
254 Floy 15942 4
54 Florencio 12739 5
447 Geoffrey 19858 1
327 Geoffrey 19223 2
335 Grant 19100 3
454 Giuseppe 16175 4
83 Gardner 15235 5
373 Hilario 19507 1
35 Hanna 19276 2
200 Halle 18150 3
491 Hailee 17521 4
411 Hermann 17018 5
21 Idella 7440 1
177 Izabella 5536 2
115 Isai 4164 3
412 Izabella 2112 4
275 Imani 573 5
195 Joannie 19374 1
8 Jacquelyn 19092 2
48 Jalon 18861 3
251 Jamie 18768 4
367 Joanny 17600 5
282 Kendra 19278 1
421 Kendra 19213 2
363 Kaylin 18977 3
96 Kaylie 18423 4
310 Katrine 17754 5
146 Lonzo 19778 1
194 Leonora 18258 2
399 Laurine 16847 3
137 Leslie 16718 4
190 Luther 16318 5
87 Maegan 19112 1
20 Mittie 18928 2
271 Mariana 18149 3
317 Mary 18043 4
305 Maybelle 17666 5
281 Noelia 19203 1
176 Nickolas 19047 2
408 Nelson 15901 3
142 Nasir 13700 4
366 Nicole 10694 5
423 Ova 19759 1
487 Osborne 19539 2
438 Ozella 18911 3
375 Ora 18270 4
414 Onie 17358 5
52 Pascale 19658 1
39 Pearlie 17621 2
364 Price 14177 3
161 Precious 10337 4
294 Paula 9162 5
70 Quincy 18343 1
73 Quincy 16631 2
192 Quentin 13578 3
131 Rodger 19776 1
231 Royal 19033 2
313 Rocky 19008 3
13 Rossie 18403 4
45 Rosanna 15992 5
418 Sydnee 19810 1
470 Sadie 19189 2
123 Shanna 18862 3
485 Savanah 18664 4
302 Steve 16412 5
406 Toney 18283 1
28 Tremaine 16400 2
98 Taurean 15911 3
278 Tremaine 14391 4
311 Treva 14026 5
239 Ubaldo 11630 1
78 Valentina 17736 1
458 Vita 17527 2
170 Vergie 16971 3
158 Vance 15089 4
272 Veronica 12027 5
102 Willis 18155 1
329 Ward 14919 2
156 Westley 14867 3
136 Winnifred 14315 4
6 Winnifred 13580 5
323 Yolanda 17920 1
155 Yesenia 6164 2
402 Zachary 19129 1
37 Zaria 5398 2
See running example at DB Fiddle.

Delete previous entry and update table with current entry - mySql

Say below is my table
entryID ID Number locationId timestamp
331 136 7 1 5/30/2018 9:23
332 136 7 1 5/30/2018 9:25
333 136 9 1 5/30/2018 9:25
334 136 11 1 5/30/2018 9:25
335 136 11 1 5/30/2018 9:25
336 136 9 1 5/30/2018 9:26
337 137 1 2 6/4/2018 8:45
338 137 2 2 6/4/2018 8:47
339 137 7 2 6/4/2018 8:47
340 137 7 2 6/4/2018 8:47
I would want to filter them by ID and locationId, delete the duplicate rows ("Number" is the column which carries duplicate values) and see the results as shown below after querying the table filtered by locationId = 1.
entryID ID Number locationId timestamp
332 136 7 1 5/30/2018 9:25
335 136 11 1 5/30/2018 9:25
336 136 9 1 5/30/2018 9:26
337 137 1 2 6/4/2018 8:45
338 137 2 2 6/4/2018 8:47
339 137 7 2 6/4/2018 8:47
340 137 7 2 6/4/2018 8:47
If locationId = 2, below is the result I would expect to see.
entryID ID Number locationId timestamp
331 136 7 1 5/30/2018 9:23
332 136 7 1 5/30/2018 9:25
333 136 9 1 5/30/2018 9:25
334 136 11 1 5/30/2018 9:25
335 136 11 1 5/30/2018 9:25
336 136 9 1 5/30/2018 9:26
337 137 1 2 6/4/2018 8:45
338 137 2 2 6/4/2018 8:47
340 137 7 2 6/4/2018 8:47
The requirement is poorly explained. Nevertheless, assuming that timestamp really is a timestamp, then I suspect that you're after something like this...
(Remember to back up your data prior to deleting anything!!!)
DELETE x
FROM my_table x
LEFT
JOIN
( SELECT locationid
, number
, MAX(entryid) entryid
FROM my_table
GROUP
BY locationid
, number
) y
ON y.locationid = x.locationid
AND y.number = x.number
AND y.entryid = x.entryid
WHERE y.entryid IS NULL;

How to find the last six rows(dynamic) sum of one column based on another column

BallByBallID Deliveries RunsScored BowlPlayerId BatPlayerId
109 0 1 127 4
110 0.1 2 127 6
111 0.2 3 127 6
112 0.3 4 127 4
113 0.4 6 127 4
114 0.5 6 127 4
230 0 1 162 4
231 0.1 2 162 6
232 0.2 3 162 6
233 0.3 4 162 4
234 0.4 5 162 4
235 0.5 6 162 6
236 1 1 169 4
237 1.1 2 169 6
238 1.2 3 169 6
239 1.3 4 169 4
240 1.4 5 169 4
241 1.5 6 169 6
I have data in the above mentioned format. Now i want to find the sum of RunsScored and BowlPlayerId for last inserted data (the data is dynamic the last six may change at any time) based on BallByBallId.
I tried to find the solution by using like this.........
SELECT SUM(RunsScored) from (select BallByBallId from BallByBall ORDER BY BallByBallId DESC LIMIT 6);
It is giving total some......
SELECT SUM(RunsScored) from (SELECT top 6 * from BallByBall ORDER BY BallByBallId DESC) A GROUP BY A.BowlPlayerID
SELECT SUM(RunsScored+BowlPlayerID)
FROM from BallByBall group by BallByBallId limit 6;
http://sqlfiddle.com/#!2/f3ab78/10

Update with order by in MySQL

Have this table:
ID SEQ C2 C3 C4 C5
359 1 287 1 2 1
360 1 287 1 1 1
361 2 287 1 2 1
362 2 287 1 1 1
363 4 287 1 2 1
368 4 287 1 2 1
369 5 287 1 1 1
370 7 287 1 2 1
371 4 287 1 1 1
372 6 287 1 2 1
And want to update only the SEQ column to this output:
ID SEQ C2 C3 C4 C5
359 1 287 1 2 1
360 1 287 1 1 1
361 2 287 1 2 1
362 2 287 1 1 1
363 3 287 1 2 1
368 4 287 1 2 1
369 3 287 1 1 1
370 5 287 1 2 1
371 4 287 1 1 1
372 6 287 1 2 1
Column c2, c3, c4, c5 defines a service. Column SEQ defines the version, ID=361 is a new version of service defined in ID 359.
It order by columns C2, C3, C4, C5, and removes the gap in sequence (SEQ column).
Thanks
Done!
SET #rownumber = 0;
update table t set t.SEQ = (if(t.seq<#rownumber,#rownumber:=1,#rownumber:=#rownumber+1))
order by t.C2, t.C3, t.C4, t,C5, t.SEQ;

Selecting duplicate entries from a table and getting all the fields from the duplicate rows

I have a table like this.
id day1 day2 day3
1 411 523 223
2 413 554 245
3 417 511 209
4 420 515 232
5 422 522 212
6 483 567 212
7 456 512 256
8 433 578 209
9 438 532 234
10 418 555 223
11 460 510 263
12 453 509 245
13 441 524 233
14 430 543 261
15 456 582 222
16 444 524 241
17 478 511 211
18 421 583 222
I want to select all the IDs that have duplicate values in day2.
I'm doing
select day2,count(*) from resultater group by day having count(*)>1;
Is it possible to list all the IDs within the groups?
select day2,count(*), group_concat(id)
from resultater
group by day
having count(*)>1;
should do the trick.