Stored procedure with strings - mysql

I'm trying to figured out how to use insert statement in a stored procedure.
I want to put data into a table
like this (concept, a, b, c, d, e, f, g)
but i want to get the result like this:
concept a b
concept c d
concept d e
concept f g
I think i need a string for this?
how can i create the string?

The Question is Kinda Vague but this should work you just need to insert multiple values in your table, to indicate a new row.
Sample:
INSERT INTO example
(Concept, element1, Element2)
VALUES
(Concept,a,b),
(Concept,c,d),
(Concept,e,f),
(Concept,g,h);
output:
Concept | Element1 | Element2 // table headers
concept | a | b
concept | C | D
concept | e | f //table elements
concept | g | h
or look Here for more :)

Related

How to Access Temp Column Alias in Mysql

I want to Access temporarily created column
Please see below code example
Note: I have created one stored procedure for GP calculation It has
very long I want to simplify some calculations code.
SELECT 25 AS A,35 AS B, SUM(A+B) AS C
I know syntax is wrong but I want like below
| A | B | C |
| 25 | 35 | 60 |
You can either store values in the temp table.
SELECT A,
B,
Sum(A + B) C
FROM (SELECT 25 AS A, 35 AS B) AS TempTable;

Access SQL : How to create a crosstab query with a potentially empty row

Suppose I have a database that contains two different types of information about certain unique objects, say their 'State' and 'Condition' to give a name to their classifiers. The State can take the values A, B, C or D, the condition the values X or Y. Depending on where I am sourcing data from, sometimes this database lacks entries for a particular pair.
From this data, I'd like to make a crosstab query that shows the count of data with a given State and Condition combination, but to have it still yield a row even when a given row is a 0. For example, I'd like the following table:
Unit | State | Condition
1 | A | X
2 | B | Y
3 | C | X
4 | B | Y
5 | B | X
6 | B | Y
7 | C | X
To produce the following crosstab:
Count | X | Y
A | 1 | 0
B | 1 | 3
C | 2 | 0
D | 0 | 0
Any help that would leave blanks instead of zeroes is fit for purpose as well, these are being pasted into a template Excel document that requires each crosstab to have an exact dimension.
What I've Tried:
The standard crosstab SQL
TRANSFORM Count(Unit)
SELECT Condition
FROM Sheet
GROUP BY Count(Unit)
PIVOT State;
obviously doesn't work as it doesn't raise the possibility of a D occurring. PIVOTing by a nested IIf that explicitly names D as a possible value does nothing either, nor does combining it with an Nz() around the TRANSFORM clause variable.
TRANSFORM Count(sheet.unit) AS CountOfunit
SELECT AllStates.state
FROM AllStates LEFT JOIN sheet ON AllStates.state = sheet.state
GROUP BY AllStates.state
PIVOT sheet.condition;
This uses a table "AllStates" that has a row for each state you want to force into the result. It will produce an extra column for entries that are neither Condition X nor Condition Y - that's where the forced entry for state D ends up, even though the count is 0.
If you have a relatively small number of conditions, you can use this instead:
SELECT AllStates.state, Sum(IIf([condition]="x",1,0)) AS X, Sum(IIf([condition]="Y",1,0)) AS Y
FROM AllStates LEFT JOIN sheet ON AllStates.state = sheet.state
GROUP BY AllStates.state;
Unlike a crosstab, though, this won't automatically add new columns when new condition codes are added to the data. It can also be cumbersome if you have many condition codes.

select multiple columns from multiple tables except certain columns

I have three tables.
The first table is like:
+----+----+----+
| id | x | y |
+----+----+----+
The second and third tables are like:
+----+----+----+----+----+----+----+----+----+----+----+----+
| id | Z1 | Z2 | Z3 | .. | .. | .. | .. | .. | .. | .. | Zn |
+----+----+----+----+----+----+----+----+----+----+----+----+
n is quite large, about 800-900.
I know it is quite ugly tables and database. But it is a raw data set and a learning set of a certain experiment. Please, just ignore it.
And a skeleton of a query is like:
'SELECT a.*, b.*, c.* \
FROM `test_xy` a, `test_1` b, `test_2` c \
WHERE a.id = b.id AND b.id = c.id'
What I concern is, the result with the query includes id field three times. I want id field to appear just one time at the front of the result.
I can do it by slicing the result table (by Python, MATLAB, etc.)
But, is there a better way to do this with a large number of columns? I mean, can id field of the second and third tables be excluded at the query stage?
The answer is the USING syntax: MySQL specific by the way. http://dev.mysql.com/doc/refman/5.5/en/join.html. Learn to use JOINs before you do anything else; putting the jon condition into the where clause is just plan wrong.
SELECT a.*, b.*, c.*
FROM `test_xy` a JOIN `test_1` b USING(`id)
JOIN `test_2` c USING(`id)

Haskell - Types, Enums, and Functions

Good morning everyone,
Here's what I'm working on today, and the issue I'm running in to:
--A
data Row = A | B | C | D | E | F | G | H | I | J deriving (Enum, Ord, Show, Bounded, Eq, Read)
data Column = One | Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten deriving (Enum, Ord, Show, Bounded, Eq, Read)
--B
data Address = Address Row Column deriving (Show, Read, Eq)
Then a few lines later I get to the problem child:
toAddress r c = Address(toEnum r, toEnum c)
I need to feed Address a Row and Column, but I need to turn r and c into Row and Column (not Ints)
Obviously toAddress is not structured correctly to carry out this task. The requirement is as follows:
Write a function toAddress that takes in a row and column, each in [0
− 9]. Construct an Address and return it. Use toEnum to index into
your Row and Column enums lists.
Does anyone have any suggestions on how to accomplish what I'm going for here?
Thank you!
You got the syntax wrong.
A function application of a function f :: A -> B -> C in haskell looks like this f a b and not f(a,b). f(a,b) still is correct syntax but not what you want: it passes only one parameter to the function (i.e. the tuple consisting of a and b).
So the correct implementation of toAddress looks like this:
toAddress r c = Address (toEnum r) (toEnum c)

Influencing how mysql-cli-client displays results from select queries

Is it possible to alter the way mysql on CL displays a result from select. This questions is aimed at a link or the propper term for this feature, so I can google it myself.
But specifically - is it possible to have a select result displayed as:
A: a
B: b
C: c
instead of:
A | B | C
----------
a | b | c
?
select * from Table\G
you end the query with a \G instead of a semicolon.