I have the following data in the dataset
Key Assignee Sev InOps InTek
1 A 1 Y Y
2 B 2 Y N
3 C 3 N Y
Need to plot the chart as follows so that I get
Sev on X Axis
Count(Key) on Y
Assignee belongs to Ops (Y) as Ops bar
Assignee belongs to Tek(Y) as Tek bar -For each severity we will have two bars then , one for Ops and another for Tek
which will show as follows
Sev 1 Ops Tek
1 1
Sev2 1 0
Sev3 0 1
I have the chart configuration done as follows
In Count I have dragged the Key column
In Category group I have the Sev column
in the series group , do I need to put two series opscolumn and tek respectively ?
The simplest way to do this, if possible, would be to pivot the data when generating the Dataset, i.e. having something like this:
From here it's trivial to create the Chart - Series based on InType, Category based on Severity and the data is a Count of Key.
If you can't pivot your data, create a Chart like this:
The expression for the first Chart Series is:
=Sum(IIf(Fields!InOps.Value = "Y", 1, 0))
and the second:
=Sum(IIf(Fields!InTek.Value = "Y", 1, 0))
It's also useful to set a custom Legend text for each of the Series:
Either way, you get the required result:
Related
new to SQL.
I have the following set of data
A X Y Z
1 Wind 1 1
2 Wind 2 1
3 Hail 1 1
4 Flood 1 1
4 Rain 1 1
4 Fire 1 1
I would like to select all distinct 'A' fields where for all rows that contain A have flood and rain.
So in this example, the query would return only the number 4 since for the set of all rows that contain A = 4 we have Flood and Rain.
I need the values of A where for a given value 'a' in A, there exists rows with 'a' that must contain all of the following fields provided (in the example Flood and Rain).
Please let me know if you need further clarification.
I need the values of A where for a given value 'a' in A, there exists rows with 'a' that must contain all of the following fields provided (in the example Flood and Rain).
You can use aggregation, and filter with a having clause:
select a
from mytable t
where x in ('Flood', 'Rain') -- either one or the other
having count(*) = 2 -- both match
If tuples (a, x) tuples are not unique, then you want having count(distinct x) = 2 instead.
You Shooud use count(distinct X) group by A and having
count(distinct...) avoid situation where you have two time the same value for X
select A
from my_table
WHERE x in ('Flood', 'Rain')
group A
having count(distinct X) = 2
I have a blast result in table format. Below are the first three columns. The first column is the query ID (in this example we have 2 queries; 6031753 and 60317532), and the second column is the hits against the query sequence and have 3 parts
a) swiss prot id sp|Q10CQ1|
b) gene name MAD14
c) organism ORYSJ
I would like to make the bar chart of genes which are present and how many times they appear against each query.
For example for the first query (60317531)
MAD14 2 times
MAD15 1 time
AGL8 2 time
AP1 3 time
Fields: query_id subject_id %_identity
gi|60317531|gb|AAX18712.1| sp|Q10CQ1|MAD14_ORYSJ 84.21
gi|60317531|gb|AAX18712.1| sp|P0C5B1|MAD14_ORYSI 83.40
gi|60317531|gb|AAX18712.1| sp|Q6Q9I2|MAD15_ORYSJ 68.91
gi|60317531|gb|AAX18712.1| sp|Q42429|AGL8_SOLTU 57.20
gi|60317531|gb|AAX18712.1| sp|O22328|AGL8_SOLCO 58.00
gi|60317531|gb|AAX18712.1| sp|Q41276|AP1_SINAL 65.79
gi|60317531|gb|AAX18712.1| sp|D7KWY6|AP1_ARALL 65.79
gi|60317531|gb|AAX18712.1| sp|Q8GTF4|AP1C_BRAOB 64.21
gi|60317532|gb|AAX18713.1| sp|B4YPV4|AP1C_BRAOA 64.21
gi|60317532|gb|AAX18713.1| sp|Q96355|1AP1_BRAOT 64.21
gi|60317532|gb|AAX18713.1| sp|P0DI14|AP1_BRARP
In the bar chart the x axis should be genes, the y axis should be the frequency, and the query ID would be the title of the graph.
Is there any automatic way I can do this? I have ~40,000 queries and around ~100 hits against each query in a single file.
Step1: Extract the 2nd Col form your output file using:
awk '{print$2}'
Step2: Then open the file in vim editor and type the following command:
:%s!*..*_!!g
Step3: Use this file to plot R.
data <- read.table("ur_file_name.txt", header=F, sep=" ")
barplot(data$V2, xlab="Genes", ylab="Frequency", main="Query ID")
I am new to SSRS. I am trying to build a report which has a percentage calculation from 2 variables. What happens is that it calculates percentages at the lowest level and adds them at highest level, so I am getting a percentage more than 100
Is there any way this percentage can be done at an aggregated higher level?
Sample data:
Dept Store item SOH Range_count ( variable 1 ) OOS_count ( Variable 2 ) OOS_PERC ( Var 3 )
A X i1 10 1 ( ALWAYS 1) 0 ( IF soh <=0 ,1,ELSE 0) 0 ( var2/var1 )
A X I2 0 1 1 1
A X I3 0 1 1 1
At the summary level I get the following data:
Dept Range_count OOS_Count OOS_Perc
A 3 2 2 ( I am expecting 2 / 3 )
How do I achieve this in SSRS?
Your expression will be:
=Sum(Fields!OOS_Count.Value) / Sum(Fields!Range_Count.Value)
Sum will aggregate at the scope level, which in your department group footer is per department. You can put the same formula in your table footer and it will operate over the scope of the table - that is, for all data reported.
Trying to wrap my head around how to do this query - I want to return a list of client records and need to exclude clients if they had only a specific value and no other values.
For example
c# value
1 X
1 Y
2 X
3 Y
I want all the records for clients 1 and 3, since they had a value other than X. I do not want client 2, because that client had ONLY X.
I for example want returned in this case:
1 X
1 Y
3 Y
Of course, I could have lots of other records with other client id's and values, but I want to eliminate only the ones that have a single "X" value and no other values.
Maybe using a sub-query?
Try this:
SELECT client, value FROM myTable where `client` in
(select distinct(client) from myTable where value !='X');
Returns:
Client Value
1 X
1 Y
3 Y
Something like this
SELECT ABB2.*
FROM
mytable AS ABB2
JOIN
(SELECT c
FROM mytable
WHERE value <> "X"
GROUP BY c) AS ABB1 ON ABB1.c = ABB2.c
GROUP BY ABB2.c, ABB2.value
It's faster than using a WHERE clause to identify the sub query results (as in Mike's answer)
I have a strange query to perform from a website. I have sets of arrays that contain pertinent ids from a many tables - 1 table per array. For example (the array name is the name of the table):
Array Set 1:
array "q": 1,2,3
array "u": 1,5
array "k": 7
Array Set 2:
array "t": 2,12
array "o": 8, 25
Array Set 3 (not really a set):
array "e": 5
I have another table, Alignment, which is not represented by the arrays. It performs a one to many relationship, allowing records from tables q,u, and k (array set 1, and recorded as relType/relID in the table) to be linked to records from t and o (array set 2, recorded as keyType/keyID) and e (array set 3, recorded as keyType/keyID). Example below:
Table: Alignment
id keyType keyID relType relID
1 e 5 q 1
2 o 8 q 1
3 o 8 u 1
4 t 2 q 2
5 t 2 k 7
6 t 12 q 1
So, in record 6, a record with an id of 12 from table t is being linked to a record with an id of 1 from table q.
I have to find missing links. The ideal state is that each of the ids from array set 1 have a record in the alignment table linking them to at least 1 record from array set 2. In the example, alignment record 1 does not count towards this goal, because it aligns a set 1 id to a set 3 id (instead of set 2).
Scanning the table, you can quickly see that there are some missing ids from array set 1: "q"-3 and "u"-5.
I've been doing this with script, by looping through each set 1 array and looking for a corresponding record, which generates a whole bunch of sql calls and really kills any page that calls this function.
Is there some way I could accomplish this in a single sql statement?
What would I like the results to look like (ideally):
recordset (consisting magically of data that didn't exist in the table):
relType | relID
q 3
u 5
However, I would be elated with even a binary type answer from the database - were all the proper ids found: true or false? (Though the missing records array is required for other functions, but at least I'd be able to choose between the fast and slow options).
Oh, MySQL 5.1.
User Damp gave me an excellent answer using a temporary table, a join, and an IS NULL statement. But it was before I added in the wrinkle that there was a third array set that needed to be excluded from the results, which also ruins the IS NULL part. I edited his sql statement to look like this:
SELECT *
FROM k2
LEFT JOIN alignment
USING ( relType, relID )
HAVING alignment.keyType IS NULL
OR alignment.keyType = "e"
I've also tried it with a Group By relID (i always thought that was a requirement of the HAVING clause). The problem is that my result set includes "q"-1, which is linked to all three types of records ("o","t", and "e"). I need this result excluded, but I'm not sure how.
Here's the sql I ended up with:
SELECT *
FROM k2
LEFT JOIN (
SELECT *
FROM alignment
WHERE keyType != 'e' and
(
(relType = 'q' AND relID IN ( 1, 2, 3 ))
OR
(relType = 'u' AND relID IN ( 1, 5 ))
OR
(relType = 'k' AND relID IN ( 7 ))
)
)A
USING ( relType, relID )
HAVING keyType Is Null
I have to dump the values for the IN qualifiers with script. The key was not to join to the alignment table directly.
You can try to go this route:
DROP TABLE IF EXISTS k2;
CREATE TEMPORARY TABLE k2 (relType varchar(10),relId int);
INSERT INTO k2 VALUES
('q',1),
('q',2),
('q',3),
('u',1),
('u',5),
('k',7);
SELECT * FROM k2
LEFT JOIN Alignment USING(relType,relId)
HAVING Alignment.keyType IS NULL
This should work well for small tables. Not sure about very large ones though...
EDIT
If you wanted to add a WHERE statement the query would be as follow
SELECT * FROM k2
LEFT JOIN Alignment USING(relType,relId)
WHERE Alignment.keyType != 'e'
HAVING Alignment.keyType IS NULL