LilyPond: adding a newpage - lilypond

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

Related

Lilypond: adding arrows between cells of a chord grid

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

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.

Count the number of times words appear in a text

I am trying to get the words appear the most times in different articles.
For example :
Table : Articles
Id Article
1 <b>Une santé digitale au plus près des besoins des patients et des soignants ? Direction Medidays </b> <u> <br> </u><br/>Paris, le mercredi 29 mai 2019 – Si l’on en croit l’ensemble des programmes de santé publique et tous les projets publics et privés dédiés à l’organisation des soins, les outils digitaux seront demain incontournables pour faciliter la pratique des professionnels de santé et améliorer le quotidien des patients. Pourtant, aujourd’hui, un nombre non négligeable des outils qui ont déjà été développés ne se différencient guère de gadgets au pire ou ne présentent pas de valeur ajoutée fondamentale par rapport aux systèmes classiques au mieux. <br/><b>Quarante-huit heures d’effervescence</b><br/>Inclure les professionnels de santé et les représentants de patients dans la conception des projets digitaux est sans doute la voie à suivre pour corriger cet écueil. Aussi, étaient-ils des participants de premier plan lors des Medidays, premier hackaton e-santé organisé par l’Assistance publique – hôpitaux de Paris (AP)-(HP) et Doctolib le week-end dernier. Pendant quarante-huit heures, dans une belle effervescence, vingt-deux équipes comptant des professionnels de santé, des cadres de santé, des patients, des développeurs, des designers ou encore des graphistes ont travaillé sans relâche pour présenter à un jury de spécialistes des projets innovants mais également adaptés à la pratique quotidienne. <br/><b>De la dépression du post partum au coaching des infirmières hospitalières</b><br/>Cinq programmes sur les trente-cinq présentés ont retenu l’attention. Ils ont tous en commun de promouvoir une amélioration directe de la prise en charge des patients ou de la vie pratique des professionnels de santé. Ainsi, « <i>Docteur Simone</i> » est une application proposée par Anne-Charlotte Dimmy pour améliorer la prévention de la dépression post-partum. « Chat marche » imaginée par Flavien Quijoux promet grâce à un système de reconnaissance d’image de lutter contre la chute des personnes âgées. Quant à « <i>Post hop</i> », coup de cœur de l’AP-HP présentée par Romain Laurent, elle est dédiée à la rééducation améliorée après chirurgie. <br/>Du côté de l’amélioration de la vie pratique des professionnels de santé, deux applications ont été saluées : Supply Med, dessinée par Rubin Soudry, une marketplace digitale dédiée aux fournitures médicales dentaires et Coach My Nurse, programme de coaching destiné aux infirmières hospitalières produite par Martin Louvel. L’ensemble de ces applications bénéficieront de soutiens technologiques afin d’assurer leur développement. « <i>Nous sommes heureux de pouvoir faire émerger et d’accompagner des projets qui permettront, demain, de contribuer à la transformation du système de santé. En 48 heures, des premières solutions extrêmement prometteuses ont émergé. C’est la preuve que lorsque plusieurs acteurs de la santé se mettent en commun pour réfléchir au futur de la santé en France, des projets utiles et innovants peuvent voir le jour. Chez Doctolib, nous sommes très fiers d’avoir rendu cela possible</i> », a observé Stanislas Niox-Chateau, co-fondateur et président de Doctolib et membre du jury de la 1ère édition de Medidays. <br/> <b>Léa Crébat </b> </p>
I use this SQL query:
select DISTINCT val, cnt as result from(
select (substring_index(substring_index(t.article, ' ', n.n), ' ', -1)) val,count(*) as cnt
from articles t cross join(
select a.n + b.n * 10 + 1 n
from
(select 0 as n union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6
union all select 7 union all select 8 union all select 9) a,
(select 0 as n union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6
union all select 7 union all select 8 union all select 9) b
order by n
) n
where n.n <= 1 + (length(t.article) - length(replace(t.article, ' ', '')))
AND (substring_index(substring_index(t.article, ' ', n.n), ' ', -1)) NOT REGEXP '^[0-9]+$'
AND (substring_index(substring_index(t.article, ' ', n.n), ' ', -1)) > ''
group by val
order by cnt desc
) as x
ORDER BY `result` DESC LIMIT 5
For the moment I can get :
val result
des 8
de 4
et 4
santé 3
au 2
But I think there is a problem because if I search by hand in the article, I see that "des" appears 26 times, "de" appears 34 times, "et" appears 11 times, "santé" 12 times and "au" appears 5 times.
How can I get the exact number of times each word appears in the text?
You are only counting among the first 100 words. You can extend this to 1000:
(select a.n + b.n * 10 + c.n * 100 + 1 as n
from (select 0 as n union all select 1 union all select 2 union all select 3 union all
select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
) a cross join
(select 0 as n union all select 1 union all select 2 union all select 3 union all
select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
) b cross join
(select 0 as n union all select 1 union all select 2 union all select 3 union all
select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
) c
) n
I have to use REPLACE() to remove some special characters
SQL DEMO
SELECT val, count(*)
FROM (
SELECT
DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(message, ' ', n.digit + m.digit*10 + o.digit*100 + p.digit*1000 +1), ' ', -1) val,
n.digit + m.digit*10 + o.digit*100 + p.digit*1000 as word
FROM
(SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(message, '<b>', ' '), '</p>', ' '), '</b>', ' '), '<br/>', ''), '<br>', ''), ',', ' '), '<i>', ' '), '</i>', ' '), '.', ' '), '<u>', ' '), '</u>', ' ') as message
FROM Table1
) as Table1
CROSS JOIN (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) n
CROSS JOIN (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) m
CROSS JOIN (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) o
CROSS JOIN (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) p
ON LENGTH(REPLACE(message, ' ' , '')) <= LENGTH(message)-n.digit + m.digit*10 + o.digit*100 + p.digit*1000
) as T
WHERE val <> ' '
GROUP BY val
ORDER BY COUNT(*) DESC

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