SQL Server : how to combine two select queries from the same table and take the result on Column -
I want to add two questions to the same table.
Here's my table:
Date ##### | Value1 Value 2 Value 3 type ------------------------------------------------- ----- 23/04/2014 | 1,2 | 12,3 | 10 | Green 23/04/2014 | 11,2 | 3 | 10,3 | Non-green 24/04/2014 | 10 9 3 | 11 | Green 24/04/2014 | 2,3 | 12,3 | 8 | Green 24/04/2014 | 10 | 1 | 11 | Non-green 25/04/2014 | 10 | 2 | 10,8 | Non-green 25/04/2014 | 1,4 | 5 | 12 | The green
values are of the decimal
type. Value 1, Value 2, Value 3> = 10 Expected Result:
Date ##### | Green | Non-Green ------------------------------ 23/04/2014 | 2 | 2 24/04/2014 | 3 | 2 25/04/2014 | 1 | 2
Green and non-green values were counted from> value 1, value 2, value of 3 = 10, this is my first query:
< Code> String = as the slow string "Selection D, LW, CAT FOR (Selection Top 7 [Date] AS [Type] as LW, SUM (case when value 1> = 10 and 1 ELSE 0 END + case when the value of 2> = 10 then 1 ELSE 0 END + case when the value is 3> = 10 THEN 1 ELSE 0 END) Type in the TB booth where type = 'green' group [date], [ Type] order [date] deess By x command, DASC "
it displays:
Date ##### | Type ------------------------ 23/04/2014 | 2 | Green 24/04/2014 | 3 | Green 25/04/2014 | 1 | Green
My second query:
String = as the slow stroke = "Select D, LW, cnt FROM" SELECT TOP 7 [date] AS d , As the [type] LW, SM (in case when value 1> = 10 and 1 ELSE 0 end + case when value2> = 10 and 1 ELSE 0 END + case when value3> 10 and 1 ELSE 0 END) where type = 'non-green' group [date], [type] order [date] by DESC) x order by DASC "
Displays this:
Dina Of ##### | Type ------------------------ 23/04/2014 | 2 | Non-green 24/04/2014 | 2 | Non-green 25/04/2014 | 2 | Non-green
I want to add both queries to become one and the result of date , green and non Green . Assume that I have a lot of groups, I want it to display only the last 7 groups based on the code <7>.
How to do it anyway? I tried to use the union or PIIT on other SO posts, but I do not have any code on how to apply it to my code.
Sorry, I am posting this question tomorrow, this is an edit with the expected result ....
Thank you in advance ....
SELECT d, sum (case LW = 'green' THEN cnt ELSE 0 END) [Date] [type] as ASD, LW, case when value 1> = 10 then 1 ELSE 0 END + case when value 2> = 10 then 1 ELSE 0 END + case when value is 3> = 10 and 1 ELSE 0 in the end by typing TBBoth WR (in the 'green', 'non-green') with more than CNT, DNS_RNAK (date [date] by DESC) x WHERE dr & lt; DASC by D group by 8 groups
Comments
Post a Comment