Lilypond: adding arrows between cells of a chord grid - lilypond
I filled a chord grid in LilyPond which you can see the output here. I want to add some arrows to write a syncope.
I thought about adding slurs:
grille = \chordmode {
\bar "[|:"
d1(
g1)
...
But it doesn't modify anything.
Here is the code:
% LilyBin
\version "2.19.55"
#(set-global-staff-size 18)
% si cette valeur change modifier la valeur de rlineto ci-dessous
\paper {
page-breaking = #ly:page-turn-breaking
}
\header {
tagline = ##f
composer = "The Cure"
title = "Friday I'm in Love"
}
\paper {
#(set-paper-size "a4")
page-count = #1 % forçage du nombre de pages
page-breaking = #ly:page-turn-breaking
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% La fonction pour diviser une case en 2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"\\/" =
#(define-music-function
(parser location mus1 mus2) ( ly:music? ly:music? )
#{
\stopStaff
\once \override Staff.StaffSymbol.stencil =
$(lambda (grob)
(let* ((staff (ly:staff-symbol::print grob))
(X-ext (ly:stencil-extent staff X))
(Y-ext (ly:stencil-extent staff Y)))
(ly:grob-set-property! grob 'layer -10)
(ly:stencil-add
(make-line-stencil
(ly:staff-symbol-line-thickness grob)
(car X-ext) (car Y-ext) (cdr X-ext) (cdr Y-ext))
staff)))
\startStaff
\once \override ChordName.extra-offset = #'(1 . .5)
$mus1
\once \override ChordName.extra-offset = #'(3 . -3)
$mus2
\stopStaff
\startStaff
#})
%%%%%%%%%%%%%%%%%
grille = \chordmode {
\bar "[|:"
d1
g1
d1
a1
\break
b1:m
g1
d1
a1
\bar ":|]"
\break
\bar "[|:"
d1
g1
d1
a1
\break
b1:m
g1
d1
a1
\bar ":|]"
\break
g1
a1
b1:m
g1
\break
d1
a1
\stopStaff
\bar "" s \bar "" s
\break
\startStaff
d1
g1
d1
a1
\break
b1:m
g1
d1
a1
\break
d1
g1
d1
a1
\break
b1:m
g1
d1
a1
\break
d1
g1
d1
a1
\break
b1:m
g1
d1
a1
\pageBreak
\break
g1
a1
b1:m
g1
\break
d1
a1
\stopStaff
\bar "" s \bar "" s
\break
\startStaff
\set Score.repeatCommands = #'((volta "4 X"))
\bar "[|:"
b1:m
c:9
d1
a1
\set Score.repeatCommands = #'((volta "#f"))
\bar ":|]"
}
marques = \relative c' {
s1 ^\markup \bold \box \fontsize #7 Intro s1*7
s1 ^\markup \bold \box \fontsize #7 VerseI s1*7
s1 ^\markup \bold \box \fontsize #7 Chorus s1*7
s1 ^\markup \bold \box \fontsize #7 VerseII s1*7
s1 ^\markup \bold \box \fontsize #7 Solo s1*7
s1 ^\markup \bold \box \fontsize #7 VerseIII s1*7
s1 ^\markup \bold \box \fontsize #7 ChorusII s1*7
s1 ^\markup \bold \box \fontsize #7 Bridge s1*7
}
\score{
\layout {
indent = 0 % pas de décalage même à la première ligne
\context {
\Score
\omit Clef % Cacher la clef
\omit TimeSignature % cacher la métrique
\omit BarNumber % cacher les numéros de mesures
\override SpacingSpanner.strict-note-spacing = ##t % permet d’avoir toutes les mesures de même longueur
proportionalNotationDuration = #(ly:make-moment 1/16) % durée de référence pour espacer la musique
}
}
<<
\new Staff \with { % la portée qui recevra les repères
\remove "Staff_symbol_engraver" % cacher la portée
}
\marques % la variable contenant les repères
\new ChordNames \with { % la portée qui recevra la grille harmonique
\override ChordName.extra-offset = #'(10 . -1 ) % déplacer les noms des accords
\override BarLine.bar-extent = #'(-5 . 5) % définir la taille des barres de mesures
\consists "Bar_engraver" % afficher les barres de mesures
\override StaffSymbol.line-positions = #'( -10 10 ) % definir une portée de 2 lignnes
\consists "Staff_symbol_engraver" % afficher la portée
\consists "Percent_repeat_engraver" % afficher le signe "%" pour les mesures répétées
}
\grille % la variable contenant la grille harmonique proprement dite
>>
}
I'm new to Lilypond myself, but I was able to get the arrow by creating a custom shape in the markup of a measure /mark.
See this example (based on your original output): http://lilybin.com/k7kykq/142
Please forgive the fact that I hard-coded the shape. I don't yet know of an easier way of drawing it.
Idea inspired by: http://lsr.di.unimi.it/LSR/Item?id=1050
Related
LilyPond: adding a newpage
I filled a chord grid in LilyPond which you can see the output here. It takes the space of a full-page so I wanted to add a few more lines to a new page. I tried to add it in my score but this stack all the cells the one on the others. So how can I add a new page in LilyPond? Here is my attempt: % LilyBin \version "2.19.55" #(set-global-staff-size 18) % si cette valeur change modifier la valeur de rlineto ci-dessous \header { tagline = ##f composer = "The Cure" title = "Friday I'm in Love" } \paper { #(set-paper-size "a4") page-count = #1 % forçage du nombre de pages } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % La fonction pour diviser une case en 2 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "\\/" = #(define-music-function (parser location mus1 mus2) ( ly:music? ly:music? ) #{ \stopStaff \once \override Staff.StaffSymbol.stencil = $(lambda (grob) (let* ((staff (ly:staff-symbol::print grob)) (X-ext (ly:stencil-extent staff X)) (Y-ext (ly:stencil-extent staff Y))) (ly:grob-set-property! grob 'layer -10) (ly:stencil-add (make-line-stencil (ly:staff-symbol-line-thickness grob) (car X-ext) (car Y-ext) (cdr X-ext) (cdr Y-ext)) staff))) \startStaff \once \override ChordName.extra-offset = #'(1 . .5) $mus1 \once \override ChordName.extra-offset = #'(3 . -3) $mus2 \stopStaff \startStaff #}) %%%%%%%%%%%%%%%%% grille = \chordmode { \bar "[|:" d1 g1 d1 a1 \break b1:m g1 d1 a1 \bar ":|]" \break \bar "[|:" d1 g1 d1 a1 \break b1:m g1 d1 a1 \bar ":|]" \break g1 a1 b1:m g1 \break d1 a1 \stopStaff \bar "" s \bar "" s \break \startStaff d1 g1 d1 a1 \break b1:m g1 d1 a1 \break d1 g1 d1 a1 \break b1:m g1 d1 a1 \break d1 g1 d1 a1 \break b1:m g1 d1 a1 \break g1 a1 b1:m g1 \break d1 a1 \stopStaff \bar "" s \bar "" s \bar ".." } marques = \relative c' { s1 ^\markup \bold \box \fontsize #7 Intro s1*7 s1 ^\markup \bold \box \fontsize #7 VerseI s1*7 s1 ^\markup \bold \box \fontsize #7 Chorus s1*7 s1 ^\markup \bold \box \fontsize #7 VerseII s1*7 s1 ^\markup \bold \box \fontsize #7 Solo s1*7 s1 ^\markup \bold \box \fontsize #7 VerseIII s1*7 s1 ^\markup \bold \box \fontsize #7 Chorus s1*7 } \score{ \layout { indent = 0 % pas de décalage même à la première ligne \context { \Score \omit Clef % Cacher la clef \omit TimeSignature % cacher la métrique \omit BarNumber % cacher les numéros de mesures \override SpacingSpanner.strict-note-spacing = ##t % permet d’avoir toutes les mesures de même longueur proportionalNotationDuration = #(ly:make-moment 1/16) % durée de référence pour espacer la musique } } << \new Staff \with { % la portée qui recevra les repères \remove "Staff_symbol_engraver" % cacher la portée } \marques % la variable contenant les repères \new ChordNames \with { % la portée qui recevra la grille harmonique \override ChordName.extra-offset = #'(10 . -1 ) % déplacer les noms des accords \override BarLine.bar-extent = #'(-5 . 5) % définir la taille des barres de mesures \consists "Bar_engraver" % afficher les barres de mesures \override StaffSymbol.line-positions = #'( -10 10 ) % definir une portée de 2 lignnes \consists "Staff_symbol_engraver" % afficher la portée \consists "Percent_repeat_engraver" % afficher le signe "%" pour les mesures répétées } \grille % la variable contenant la grille harmonique proprement dite >> }
I'm stoopid. In the documentation one can read that should you want to add a new line just do: \paper { ... page-breaking = #ly:page-turn-breaking ... } And then place a \pageBreak
LilyPond missing repeat bar end line
New to LilyPond and trying to use it to transcribe some bagpipe music. In this score there are two sets of repeats, however it is not adding the repeat bar end to the first, only the second. Even if I try to force it with \bar ":|." it is just ignored. \score { \header { } { \clef "treble" \time 3/4 \hideKeySignature \repeat volta 2 { \bar ".|:" \grg a8. b16 \dblc c4 \grg e \grg a8. b16 \dblc c4~ c4 \dblb b8 \grG a \dblb b4~ b4 \grg c16. b32 \grg a16. b32 \dblc c4~ c4 \break \grg a8. b16 \dblc c4 \grg e \grg a8. b16 \dblc c4~ c4 \dblb b8 \grG a \dblb b4 \thrwd d4 \dblc c8. b16 \grg a4~ a4 %% No bar end repeat line here? } \break \repeat volta 2 { \bar ".|:" \thrwd d8. e16 \grg f4 A \grf g8 f \dble e4~ e4 \thrwd d8 c \dblb b4~ b4 \grg c16. b32 \grg a16. b32 \dblc c4~ c4 \break \thrwd d8. e16 \grg f4 A \grf g8 f \dble e4~ e4 \thrwd d8 c \dblb b4 \thrwd d4 \dblc c8. b16 \grg a4~ a4 } } } This code produces . Where I would like repeat bar end marking to go after the second line.
The reason that you aren't getting the repeat barline at the end of the first section, is that you are forcing the barline to be: \bar ".|:". LilyPond is using this as the barline definition for not only the start of the second section, but also for the end of the first section; LilyPond considers this to be a single barline event (as you'd expect if there wasn't at a line break here). If you really want to force the repeat barline definition in the middle of the piece (between the repeated sections), you should use the compound barline: \bar ":|.|:". However, in this case it much easier if you don't force the barline at all; remove this line and the \repeat volta commands will get the barlines right without it.
This seems to work. It has something to do with forcing the bar lines. \version "2.20.0" \include "bagpipe.ly" \score { \header { } { \clef "treble" \time 3/4 \hideKeySignature \repeat volta 2 { \bar ".|:" \grg a8. b16 \dblc c4 \grg e \grg a8. b16 \dblc c4~ c4 \dblb b8 \grG a \dblb b4~ b4 \grg c16. b32 \grg a16. b32 \dblc c4~ c4 \break \grg a8. b16 \dblc c4 \grg e \grg a8. b16 \dblc c4~ c4 \dblb b8 \grG a \dblb b4 \thrwd d4 \dblc c8. b16 \grg a4~ a4 %% No bar end repeat line here? } \break \repeat volta 2 { %\bar ".|:" \thrwd d8. e16 \grg f4 A \grf g8 f \dble e4~ e4 \thrwd d8 c \dblb b4~ b4 \grg c16. b32 \grg a16. b32 \dblc c4~ c4 \break \thrwd d8. e16 \grg f4 A \grf g8 f \dble e4~ e4 \thrwd d8 c \dblb b4 \thrwd d4 \dblc c8. b16 \grg a4~ a4 } } } Notice that I included the "bagpipe.ly" file and I have a version number. Be sure to post complete working examples in the future.
How to remove non-printable character ^# in perl
I have a simple perl script as below use strict; use warnings 'all'; use Text::CSV; use open ":std", ":encoding(UTF-8)"; my $in_file = $ARGV[0] or die "Usage: $0 filename\n"; my $out_file = $ARGV[1] or die "Usage: $0 filename\n"; my $csv = Text::CSV->new( { binary => 1, auto_diag => 1 }); my $out_csv = Text::CSV->new ( { binary => 1, auto_diag => 1, eol => $/, sep_char => ',', quote_char => '"', always_quote => 1}); open my $data, '<:encoding(UTF-8)', $in_file or die $!; open my $fh_out, '>:encoding(UTF-8)', $out_file or die $!; while (my $words = $csv->getline($data)) { tr/\r\n//d for #$words; tr/,/;/ for #$words; tr/"/'/ for #$words; $out_csv->print($fh_out, $words); } All it does is basically convert a csv file into more structured one which is easily understandable by a external application which has limitation. The script removes unwanted new line, commas and double quote which are entered as part user text entry. This has been working well . However recently in one of the input file we have non-printable character ^# , he script doesn't fail but the out put file have additional characters "0 Not sure if I can give an example of input file since the charcater is non-printable. Please see the command output below. cat Input.csv ObjectId,OrgId,Title,ObjectType,Type,ObjectId,Location,StartDate,EndDate,DueDate,ObjectId1,ObjectId2,ObjectId3,LastModified,IsDeleted,SortOrder,Depth,DummyId,IsHidden,ResultId,DeletedDate,CreatedBy,LastModifiedBy,DeletedBy 3386484,532947,Test,Topic,Auto,3386415,http://www.test.com ,,,,,,,2016-06-27T05:08:26.3070000Z,1,443,3,,False,,2017-02-16T00:31:39.4870000Z,,, With cat -e option you can see the non printable character. cat -e Input.csv M-oM-;M-?ObjectId,OrgId,Title,ObjectType,Type,ObjectId,Location,StartDate,EndDate,DueDate,ObjectId1,ObjectId2,ObjectId3,LastModified,IsDeleted,SortOrder,Depth,DummyId,IsHidden,ResultId,DeletedDate,CreatedBy,LastModifiedBy,DeletedBy^M$ 3386484,532947,Test,Topic,Auto,3386415,http://www.test.com ^#,,,,,,,2016-06-27T05:08:26.3070000Z,1,443,3,,False,,2017-02-16T00:31:39.4870000Z,,,^M$ Once the file goes through the script the output looks like this. With additional "0 at the end of http://www.test.com cat -e Output.csv "M-oM-;M-?ObjectId","OrgId","Title","ObjectType","Type","ObjectId","Location","StartDate","EndDate","DueDate","ObjectId1","ObjectId2","ObjectId3","LastModified","IsDeleted","SortOrder","Depth","DummyId","IsHidden","ResultId","DeletedDate","CreatedBy","LastModifiedBy","DeletedBy"$ "3386484","532947","Test","Topic","Auto","3386415","http://www.test.com "0","","","","","","","2016-06-27T05:08:26.3070000Z","1","443","3","","False","","2017-02-16T00:31:39.4870000Z","","",""$ Adding command output as per Dave's request od -ch Input.csv 0000000 357 273 277 O b j e c t I d , O r g I bbef 4fbf 6a62 6365 4974 2c64 724f 4967 0000020 d , T i t l e , O b j e c t T y 2c64 6954 6c74 2c65 624f 656a 7463 7954 0000040 p e , T y p e , O b j e c t I d 6570 542c 7079 2c65 624f 656a 7463 6449 0000060 , L o c a t i o n , S t a r t D 4c2c 636f 7461 6f69 2c6e 7453 7261 4474 0000100 a t e , E n d D a t e , D u e D 7461 2c65 6e45 4464 7461 2c65 7544 4465 0000120 a t e , O b j e c t I d 1 , O b 7461 2c65 624f 656a 7463 6449 2c31 624f 0000140 j e c t I d 2 , O b j e c t I d 656a 7463 6449 2c32 624f 656a 7463 6449 0000160 3 , L a s t M o d i f i e d , I 2c33 614c 7473 6f4d 6964 6966 6465 492c 0000200 s D e l e t e d , S o r t O r d 4473 6c65 7465 6465 532c 726f 4f74 6472 0000220 e r , D e p t h , D u m m y I d 7265 442c 7065 6874 442c 6d75 796d 6449 0000240 , I s H i d d e n , R e s u l t 492c 4873 6469 6564 2c6e 6552 7573 746c 0000260 I d , D e l e t e d D a t e , C 6449 442c 6c65 7465 6465 6144 6574 432c 0000300 r e a t e d B y , L a s t M o d 6572 7461 6465 7942 4c2c 7361 4d74 646f 0000320 i f i e d B y , D e l e t e d B 6669 6569 4264 2c79 6544 656c 6574 4264 0000340 y \r \n 3 3 8 6 4 8 4 , 5 3 2 9 4 0d79 330a 3833 3436 3438 352c 3233 3439 0000360 7 , T e s t , T o p i c , A u t 2c37 6554 7473 542c 706f 6369 412c 7475 0000400 o , 3 3 8 6 4 1 5 , h t t p : / 2c6f 3333 3638 3134 2c35 7468 7074 2f3a 0000420 / w w w . t e s t . c o m \0 , 772f 7777 742e 7365 2e74 6f63 206d 2c00 0000440 , , , , , , 2 0 1 6 - 0 6 - 2 7 2c2c 2c2c 2c2c 3032 3631 302d 2d36 3732 0000460 T 0 5 : 0 8 : 2 6 . 3 0 7 0 0 0 3054 3a35 3830 323a 2e36 3033 3037 3030 0000500 0 Z , 1 , 4 4 3 , 3 , , F a l s 5a30 312c 342c 3334 332c 2c2c 6146 736c 0000520 e , , 2 0 1 7 - 0 2 - 1 6 T 0 0 2c65 322c 3130 2d37 3230 312d 5436 3030 0000540 : 3 1 : 3 9 . 4 8 7 0 0 0 0 Z , 333a 3a31 3933 342e 3738 3030 3030 2c5a 0000560 , , \r \n 2c2c 0a0d 0000564 How can I handle this in the script , I do not want the additional "0 in the output csv. Thanks
Once you find out the numerical value for that character, you can use \x{} to specify it by that code number: s/\x{....}//g; For example, if the character is 🐱, I can find its ordinal value. I typically do that with a hex dump, but there are a variety of ways. It's U+1F431: s/\x{1F431}//g; You can also specify the code number in octal for the non-wide characters: s/\200//g; Or use those in a range in a character class: s/[\200-\377]//g; s/[\000-\037]//g; s/[\000-\037\200-\377]//g; But, there may be another thing you want to do. You might match it by a property it has (see perluniprops): s/\p{XPosixCntrl}//g Or, with an uppercase P, a property it doesn't have: s/\P{Print}//g
So, we've learned two things from your hex dump of the file: It's definitely a UTF8 file - as the first three characters are the UTF8 Byte Order Marker (or BOM). Your problematic character is actually a null (with a codepoint of zero). So, following brian's advice, you'll be able to remove the character with: s/\0//g;
I'm not sure how you discovered it was ^#, but you should be able to refer to any such thing by using \c#, where the \c stands for "CTRL-". So, if it were a SOH, \x01, and you saw it displayed as ^A, you could specify s/\cA//g to get rid of it
How to start measure halfway?
In my hymn, I need to start the first measure halfway through. It has a time of 3/4, but I have to insert two empty, non-showing eighth notes. How do I do that? I've used o4 o4 c8[ d] below for the first measure, but lilypond does not like this. What's the right way? Here's the line: o4 o4 c8[ d] e4 e4 e8[ f] g4 g4 f8[ e] d4 d4 g8[ f] e2
For upbeats, there's a special command \partial available. In your case, you should notate a quarter partial: \relative c' { \time 3/4 \partial 4 c8 d | e4 e4 e8 f | g4 g4 f8 e | d4 d4 g8 f | e2 } This results in:
MySql Combinate queries
I have a table with the records of different defects in a company. The table is something like this ITMNBR Defect Reference_Designator RepairCenter 8800RTO001700 Componente / Placa abierto U1U2 FG 8800HIB001075V Componente Equivocado (NumeroParte) R53 SB 8800HIB001075V Ensamble Incorrecto (produccion) R19 SB 8800RTO000400 Componente / Placa abierto U1 SB 8800RTO003200 Componente Polaridad Inversa ZD2 SB 8800HIB001048 NO SOLDADURA T1 SB 8800HIB001048 Componente / Placa abierto U2 SB 8800HIB001048 Componente / Placa abierto U2 SB Etc. I want to consult only the three most repetitive defects of manufacture, I made this. SELECT defect, COUNT(*) FROM reportefallas WHERE RepairCenter ='SB' AND (CREADT BETWEEN NOW() - INTERVAL 7 DAY AND NOW()) #Select the Dates AND (Defect IN ('Componente / Placa dañada X alto voltaje','Pin / Patita Quebrado','Componente / Placa Quemada','Componente Defecto Cosmetico','Falla no Duplicada','Soldadura Crackeada','Soldadura Fria','Parametros Incorrectos en la torre','Parametros Incorrectos en el dibujo','Componente dañado fisicamente','Conector mal colocado (inclinado)','Tornillo / Rondana Suelto','Pista Levantada (dañada)','Componente Ausente','Soldadura Derretida','Componente Equivocado (NumeroParte)','NO SOLDADURA','Componente/Placa no programada','Conector mal ensamblado','No se encontro problema','Tornillo / Rondana Flojo','Componente / Placa abierto','Pin Hole','Pin / Pata levantada (no Soldadura)','Componente Polaridad Inversa','Puente de Soldadura','Componente Desfasado Pad','Componente / Placa en corto','Splash de Soldadura','LEDs con VF diferente / equivocado','LEDs con VF alto','LEDs con VF bajo','Ensamble Incorrecto (produccion)','Componente posicion Equivocada (referencia)','Cable ensamblado posicion incorrecta')) GROUP BY defect ORDER BY COUNT(*) DES LIMIT 3; And I have the next result Defect COUNT(*) Componente/ Placa abierto 5 Componente / Placa dañada X alto voltaje 4 Componente dañado fisicamente 3 Now, I need a query from the same table where the defects are, with only the three most repetitive defects that I already obtained, this is the result that I want: ITMNBR Defect Reference_Designator 8800ITH001700 Componente / Placa abierto F2-U1(SHORT)-U2(SHORT) 8800ITH001700 Componente / Placa abierto F2-U1(SHORT)-U2(SHORT) 8800ITH001700 Componente / Placa abierto F2-R29-R22-R19-R32-R13-U1(SHORT)-U2(SHORT) 8800ITH001700 Componente / Placa abierto F2-R29-R22-R19-R32-R13-U1(SHORT)-U2(SHORT) 8800ITH001700 Componente / Placa abierto F2 8850HZL0015EX Componente / Placa dañada X alto voltaje C6-C7 8800HIB001084 Componente / Placa dañada X alto voltaje R7-C20-MOV1 8850HIB004205 Componente / Placa dañada X alto voltaje C21-C42 8800HIB004220 Componente / Placa dañada X alto voltaje R22 SWITH-R44 SWITH 8850HIB004206 Componente dañado fisicamente C42 8850HIB004202 Componente dañado fisicamente F1 8800HIB0131EX Componente dañado fisicamente R37 I tried the code below, but it doesn’t accept the LIMIT. SELECT ITMNBR, Defect, Reference_Designator FROM reportefallas WHERE Defect IN (SELECT defect FROM reportefallas WHERE RepairCenter='SB' AND(CREADT BETWEEN NOW() - INTERVAL 7 DAY AND NOW()) AND (Defect IN ('Componente / Placa dañada X alto voltaje','Pin / Patita Quebrado','Componente / Placa Quemada','Componente Defecto Cosmetico','Falla no Duplicada','Soldadura Crackeada','Soldadura Fria','Parametros Incorrectos en la torre','Parametros Incorrectos en el dibujo','Componente dañado fisicamente','Conector mal colocado (inclinado)','Tornillo / Rondana Suelto','Pista Levantada (dañada)','Componente Ausente','Soldadura Derretida','Componente Equivocado (NumeroParte)','NO SOLDADURA','Componente/Placa no programada','Conector mal ensamblado','No se encontro problema','Tornillo / Rondana Flojo','Componente / Placa abierto','Pin Hole','Pin / Pata levantada (no Soldadura)','Componente Polaridad Inversa','Puente de Soldadura','Componente Desfasado Pad','Componente / Placa en corto','Splash de Soldadura','LEDs con VF diferente / equivocado','LEDs con VF alto','LEDs con VF bajo','Ensamble Incorrecto (produccion)','Componente posicion Equivocada (referencia)','Cable ensamblado posicion incorrecta')) GROUP BY defect ORDER BY COUNT(*) DESC LIMIT 3) Does anyone have any ideas any ideas? Sorry for the Spanglish and the bad English, I hope you can understand.
There are several options. Previous questions on this topic have suggested using JOIN to trim down your result set instead of IN, which would look something like this: SELECT rf.ITMNBR, rf.Defect, rf.Reference_Designator FROM (SELECT defect FROM reportefallas WHERE RepairCenter='SB' AND(CREADT BETWEEN NOW() - INTERVAL 7 DAY AND NOW()) AND (Defect IN ('Componente / Placa dañada X alto voltaje','Pin / Patita Quebrado','Componente / Placa Quemada','Componente Defecto Cosmetico','Falla no Duplicada','Soldadura Crackeada','Soldadura Fria','Parametros Incorrectos en la torre','Parametros Incorrectos en el dibujo','Componente dañado fisicamente','Conector mal colocado (inclinado)','Tornillo / Rondana Suelto','Pista Levantada (dañada)','Componente Ausente','Soldadura Derretida','Componente Equivocado (NumeroParte)','NO SOLDADURA','Componente/Placa no programada','Conector mal ensamblado','No se encontro problema','Tornillo / Rondana Flojo','Componente / Placa abierto','Pin Hole','Pin / Pata levantada (no Soldadura)','Componente Polaridad Inversa','Puente de Soldadura','Componente Desfasado Pad','Componente / Placa en corto','Splash de Soldadura','LEDs con VF diferente / equivocado','LEDs con VF alto','LEDs con VF bajo','Ensamble Incorrecto (produccion)','Componente posicion Equivocada (referencia)','Cable ensamblado posicion incorrecta')) GROUP BY defect ORDER BY COUNT(*) DESC #Ordena de manera descendente LIMIT 3) AS subquery JOIN reportefallas AS rf USING (Defect) Alternatively, you could create a separate table to track the three most common defects, and periodically update that table (e.g. via a cron job). Then you would SELECT ... WHERE Defect IN this other table. Either of these methods could provide better performance, depending on the situation. If you try one and have poor performance, try the other and see if it's an improvement. (For that matter, you could also store that enormous list of defects in another table, to make your query cleaner.)
just like AirThomas said you can use a subquery.. you should also be able to do a simple select inside your IN() instead of listing out each one individually. this is another way to do the subquery though SELECT rf.ITMNBR, rf.Defect, rf.Reference_Designator FROM( SELECT ITMNBR as itm_number, defect, COUNT(*) as top_three FROM reportefallas WHERE RepairCenter ='SB' AND (CREADT BETWEEN NOW() - INTERVAL 7 DAY AND NOW()) -- Select the Dates AND (Defect IN (SELECT defect from reportefallas)) GROUP BY defect ORDER BY top_three DES LIMIT 3 )as t JOIN reportefallas rf ON rf.ITMNBR = t.itm_number