Here is my code:
\begin{lilypond}
\version "2.17.27"
\language "english"
\relative{
\time 2/4
c' c _"C.1"|
c cs |
c d |
c ds |
c e |
c f |
c g' |
c, a' |
c, as' |
c, b' |
}
\end{lilypond}
It generates this:
What I need and don't know how to do:
Remove the clef and the meter marks
Instead of "C.1" put the Russian "Ч.1"
Shift the "C.1" text below the first pitch, so it was nicely centered.
The following code should do the trick:
\version "2.17.27"
\language "english"
\relative{
\omit Staff.Clef
\omit Staff.TimeSignature
\time 2/4
c' _"Ч.1" c |
c cs |
c d |
c ds |
c e |
c f |
c g' |
c, a' |
c, as' |
c, b' |
}
Just put it into a file named document.ly (for example) and run lilypond on it:
lilypond --pdf document.ly
(replace --pdfwith --png if you want a PNG as result). This should produce a PDF with the following content:
Tested with GNU LilyPond 2.18.2 on Ubuntu Vivid (15.04).
Related
Is it possible to reduce the number of rows returned from a joined query by having results from individual tables returned in some array-like container
E.g. for a query:
SELECT a.col, b.col, c.col FROM
a INNER JOIN b ON a.id = b.id
INNER JOIN c ON a.id = c.id
where it is known a.id uniquely matches 1 row in a, b.id matches 2 rows in b and c.id matches 3 rows in c, the results would then be
+-------+-------+-------+
| a.col | b.col | c.col |
+-------+-------+-------+
| A0 | B1 | C1 |
| A0 | B2 | C1 |
| A0 | B1 | C2 |
| A0 | B2 | C2 |
| A0 | B1 | C3 |
| A0 | B2 | C3 |
+-------+-------+-------+
6 rows in set
So question is if it some how would be possible to reduce output to something like (or similar)
+-------+----------+--------------+
| A.col | b.... | c.... |
+-------+----------+--------------+
| A0 | [B1, B2] | [C1, C2, C3] |
+-------+----------+--------------+
Perhaps instead of array-like structure form strings (array like to me...), e.g. "B1,B2", "C1,C2,C3"
Note, can't use DISTINCT as b.col may contain identical values.
What if one wishes more than one column from table b, e.g.
SELECT a.col, b.col, b.col2, c.col FROM
a INNER JOIN b ON a.id = b.id
INNER JOIN c ON a.id = c.id
```
how to get a result on form (or similar)
```
+-------+------------------------+--------------+
| A.col | b.... | c.... |
+-------+------------------------+--------------+
| A0 | [[B1, B11], [B2, B21]] | [C1, C2, C3] |
+-------+------------------------+--------------+
```
Would it perhaps be possible/wise to prior to `JOIN` table a and b create a temporary table btmp with the desired output (as a string or similar).
At the end of the day I wish to access a mysql data base remotely over a line that sometimes may be quite bad, so wish to reduce the amount of data sent as far as possible without loosing required information.
This is a job for GROUP_CONCAT(). It doesn;t create arrays of values, but it does create delimited string lists. MySQL doesn't of course, have array-valued columns either in tables or result sets, so you're stuck with strings.
I believe this will do something close to what you want.
SELECT a.col,
GROUP_CONCAT(DISTINCT b.col) b
GROUP_CONCAT(DISTINCT c.col) c
FROM a
INNER JOIN b ON a.id = b.id
INNER JOIN c ON a.id = c.id -- you had a.id = b.id but that won't work.
GROUP BY a.col
I have a graph with nodes {A, B, C, D, ...} and a table which specifies the directed edges between them.
| node_1 | node_2 |
|-----------------|
| A | B |
| A | C |
| B | A |
| B | D |
| D | A |
We write A ~ B if there is an edge from A to B. So a row where node_1 = A and node_2 = B implies A ~ B. I distinguish between the following types of relations:
A = B if A ~ B and B ~ A
A > B if A ~ B and not B ~ A
A < B if B ~ A and not A ~ B
How can I retrieve all the nodes adjacent to a given node along with their type of relation? For example, a query for A on the above table should return
| node | type |
|------|------|
| B | = | (because A ~ B and B ~ A)
| C | > | (because A ~ C and not C ~ A)
| D | < | (because D ~ A and not A ~ D)
here is one way :
select node,
case when count(*) = 2 then '='
when max(ordertype) = 1 then '>'
when max(ordertype) = 2 then '<' end as type
from (select node2 node,
1 ordertype
from nodes
where node1 = 'A'
union all
select node1,
2
from nodes
where node2 = 'A') t
group by node
order by node
Hmmm . . . you can use conditional logic with aggregation:
select (case when node_1 = 'A' then node_2 else node_1 end) as other_node,
(case when count(*) = 2 then '='
when max(node_1) = 'A' then '>'
else '<'
end) as type
from nodes n
where 'A' in (node_1, node_2)
group by (case when node_1 = 'A' then node_2 else node_1 end);
Here is a db<>fiddle.
This seems like the simplest and probably the most performant solution.
first table
a.id | a.name
1 | apple
2 | peace
3 | grape
second table
b.id | b.name
1 | yellow
2 | red
3 | green
thidr relationship table
a.id | b.id
1 | 2
1 | 1
3 | 3
3 | 1
2 | 1
I want to see :
...LIKE '%pe%' and tag 'green';
peace green
grape green
This is what I tried:
SELECT *
FROM a
INNER JOIN c ON a.a_id = c.a_id
INNER JOIN b ON c.b_id = b.b_id
WHERE a.a_name LIKE '%pe%'
I'm sure there is better ways to form that query but this seems to get you what you need.
select f.name as fruit, c.name as color from
fruit_color as fc
join fruit as f on f.id = fc.fruit_id
join color as c on c.id = fc.color_id
where f.name like '%pe%' and c.name like '%green%'
Output:
fruit | color
---------------
grape | green
peace | green
sqlFiddle
I have a table with three columns, lets define it and fill it with sample data:
A | B | C |
------ | ----- | ------|
A1 | NA | NA |
A1 | B1 | NA |
NA | B1 | NA |
NA | B1 | C1 |
NA | NA | C1 |
As we can see combination (A,B,C) is unique. I need to have a select which would select exact one row using parameters :A :B :C. For example:
1) If I have :A = A1, :B = SOME_B, :C = SOME_C. It should select first row because column A has exact match while columns B and C are not applicable.
2) If I have :A = SOME_A, :B = SOME_B, :C = SOME_C. It should not return anything.
First try was:
SELECT *
FROM SAMPLE_TABLE
WHERE (A = :A OR A = 'NA') AND (B = :B OR B = 'NA') AND (C = :C OR C = 'NA');
This returned first two rows. Wrong, as expected. That is not what I want.
Second try:
SELECT *
FROM SAMPLE_TABLE
WHERE (A = :A OR (A = 'NA' AND NOT EXISTS(SELECT 1 FROM SAMPLE_TABLE WHERE A = :A AND (B = :B OR B = 'NA') (C = :C OR C = 'NA')) AND (B = :B OR B = 'NA') AND (C = :C OR C = 'NA');
It works and logic is correct, but for B and C I need to do same stuff. After that I need to modify NOT EXISTS for column A which should include NOT EXISTS for B and C, which also should include NOT EXISTS for column A and so on. I get a loop.
Any ideas how can we write simple SQL for solving such problem? Or I just miss some silly thing?
EDIT:
Oh, it's my fault, wasn't able to be clear enought. Let's look into business example (table TEAM_MATRIX):
COUNTRY|PRIORIT| TEAM |
------ | ----- | ------|
NA | NA | GLOB_T|
UK | LOW | UK_T1 |
UK | MED | UK_T2 |
UK | HIGH | UK_T3 |
US | NA | US_T |
US | LOW | US_T1 |
Coulmns country and priority can be treated as input parameters. Column team should be treated as output. Several examples:
1) Suppose we have parameters: country = FR, priority = LOW. Then output team should be GLOB_T because there is no such combination FR and LOW. (NA means that we do not care).
2) If country is US and priority is LOW => ouput team should be US_T1 because we have combination US and LOW.
3) If country is US and priority is MED => output team should be US_T because we have combination US and NA (NA means that we do not care).
Is there a way to have SQL which follows this logic?
SELECT TEAM
FROM TEAM_MATRIX
WHERE (COUNTRY = ?1 OR COUNTRY = 'NA') AND (PRIORIT = ?2 OR PRIORIT = 'NA');
Here ?1 - country parameter, ?2 - priority parameter. This does not work, for example combination ((NA, NA) -> GLOB_T) will always be selected.
Thanks!
I have the following MySQL-Statement:
SELECT norm.NormID, norm.NormName
FROM (assignment
INNER JOIN norm
ON assignment.NID = norm.NormID )
INNER JOIN wire
ON assignment.LID = wire.WireID
WHERE wire.WireID= 109
ORDER BY norm.NormName;
Now what I got are the entries from the table assignment with the NormID and NormName for that WireID.
What I want to get are the entries from the table norm, which are not setted for this WireID.
E.g.:
WireID has the norm assignment A, B, D, G.
The table norm has the entries A, B, C, D, E, F, G, H.
What I want to get from the MySQL-Statment are the entries C, E, F, H.
How can I select those left norm entries for this WireID?
With the above statement I would get:
-----------------------
| NormID | NormName |
-----------------------
| 1 | A |
| 2 | B |
| 4 | D |
| 7 | G |
-----------------------
I want to have this Table:
-----------------------
| NormID | NormName |
-----------------------
| 3 | C |
| 5 | E |
| 6 | F |
| 8 | H |
-----------------------
I think (if I understood what you asked) you can try this :
SELECT norm.NormID, norm.NormName
FROM assignment
INNER JOIN norm ON assignment.NID = norm.NormID
LEFT JOIN wire ON assignment.LID = wire.WireID
WHERE assignment.LID= 109
AND wire.wireID IS NULL
ORDER BY norm.NormName;
Edit after your comments.
I think you could use:
SELECT A.NormID, A.NormName
FROM norm A
LEFT JOIN (SELECT NID FROM assignment WHERE LID = 109) B ON B.NID = A.NormID
WHERE B.NID IS NULL
ORDER BY A.NormName;
OR
SELECT A.NormID, A.NormName
FROM norm A
WHERE NOT EXISTS (SELECT 1 FROM assignment WHERE LID = 109 AND ASSIGNMENT.NID = A.NormID)
ORDER BY A.NormName;
Try this:
select norm.NormID,norm.NormName from norm
Inner JOIN
assignment on assignment.NID = norm.NormID
where assignment.LID in(select wireID from Wire where WireID = 109)
Im not so sure coz i dont have your data
after you added a sample data the entries that are not setted with 109 wireid are these:
SELECT norm.NormID, norm.NormName
FROM assignment
inner JOIN norm
ON assignment.NID = norm.NormID
INNER JOIN wire
ON assignment.LID = wire.WireID
WHERE wire.WireID <> 109
ORDER BY norm.NormName;