sql - Oracle database subquery results in multiple rows -


Hi there is a SQL problem, and I hope the answer is very simple.

I have the database with the following structure.

  State gender birth name calculation ----- --------------- --------- --- --- AC F1923 Helen 15 AKF1926 Helen 35 AKF1927 Susan 25 AKF 1920 Helen has 15 thousand records and I want to see that the output is like this:   < Code> birth name 1910-1911-1912 - & gt; 2012 ----- ------ --------- -------- ------ Helen 5 6 12 800   

Using MS Access I was able to get some results with it:

  SELECT DISTINCT as1 birthname AS XP1, (Select the total number from AC AS, where as 1 Birth name = as2.birthname and as1.gender = as2.gender and as1.state = as2.state and as1.birthyear = as2.birthyear and at birth = 1910) as of 1910, (AC Select the total number from AS2 where as1.birthname = as2.birthname and as1.gender = as2.gender and as1.state = as2.state and as1.birthyear = as2.birthyear and at birth = 1911) 1 9 1In the form, select the total number of 2 (from AK), where as1.birthname = as2.birthname and as1.gender = as2.gender and as1.state = as2.state and as1.birthyear = as2.birthyear And birthyear = 2012) as of 2012. AS 1    

You should use conditional aggregation:

  SELECT as1.birthname AS Expr1, SUM (when birthdays = 1910 then `calculation 'and 0 end) as yr_1910, SUM (case when birthdays = 1911 then' calculation 'and 0 end) yr_1911 As, SUM (case when birth time = 1912 then 'counting' and 0 end) yr_1912 to A.K. As AS ASP Group B1 birth place;   

I'm not sure where gender and state come from. These are not included in external queries, which are likely to cause your syntax error to include them in aggregation:

  as1.birthname, as1.gender, as1 State, SUM (case when birthdays = 1910 then 'calculation' and 0 end) as yr_1910, SUM (case when birth = 1911 then 'count' and 0 end) as yr_1911, SUM ( Case when Birthday = 1912 then 'Count' and 0 End) from yr_1912 A.K. AS ASP Group B1 At birth, as1.gender, as1.state;    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -