using System;
using System.Collections.Generic;
using System.Text;
/*算法系列*/
namespace ConsoleApplication1
{
class Program
{
/*计算1+1+2+3+5+8+13*/
public int function1(int n)
{
if (n == 0)
{
return 0;
}
if (n == 1)
{
return 1;
}
else
{
return function1(n - 1) + function1(n - 2);
}
}
//快速排序从大到小
private static void QuickSort(int[] sort, int start, int end)
{
int i = start;
int j = end + 1;
int val = sort[i];
do
{
do
{
i++;
} while (sort[i] > val && i < end);
do
{
j--;
} while (sort[j] < val && j > start);
if (i < j)
{
int temp;
temp = sort[i];
sort[i] = sort[j];
sort[j] = temp;
}
} while (i < j);
sort[start] = sort[j]; sort[j] = val;
if (j > start + 1) QuickSort(sort, start, j - 1);
if (j < end - 1) QuickSort(sort, j + 1, end);
}
static void Main(string[] args)
{
/*快速排序法进行排序*/
int[] array ={ 8,22,9,12,4,5,2,1,1};
QuickSort(array, 0, array.Length - 1);
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.Read();
/*计算-1+2-3+4-5*/
/*
int sum = 0;
for (int i = 1; i <= 5; i++)
{
sum =sum+ i * Convert.ToInt32(Math.Pow(-1.0,Convert.ToDouble(i)));
}
Console.Write(sum);
Console.Read();
*/
/*计算1+1+2+3+5+8+13*/
/* Program m = new Program();
int b=m.function1(6);
Console.Write(b);
Console.Read();
* */
/*随机插入几个数并显示出来
int[] array=new int[6];
Random r=new Random();
for (int i = 0; i <= 5; i++)
{
int temp;
temp = r.Next(0, 4);
if (i == 0)
{
array[i] =temp;
}
else
{
for (int j = 0; j <i; j++)
{
if (array[j] != temp)
{
array[i] = r.Next(0, 4);
}
}
}
}
for (int i = 0; i <= 5; i++)
{
Console.Write(array[i]+" ");
}
Console.Read();
*/
}
}
}
1.一道SQL语句面试题,关于group by
表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2
------------------------------------------
create table #tmp(rq varchar(10),shengfu nchar(1))
insert into #tmp values('2005-05-09','胜')
insert into #tmp values('2005-05-09','胜')
insert into #tmp values('2005-05-09','负')
insert into #tmp values('2005-05-09','负')
insert into #tmp values('2005-05-10','胜')
insert into #tmp values('2005-05-10','负')
insert into #tmp values('2005-05-10','负')
1)select rq, sum(case when shengfu='胜' then 1 else 0 end)'胜',sum(case when shengfu='负' then 1 else 0 end)'负' from #tmp group by rq
2) select N.rq,N.勝,M.負 from (
select rq,勝=count(*) from #tmp where shengfu='胜'group by rq)N inner join
(select rq,負=count(*) from #tmp where shengfu='负'group by rq)M on N.rq=M.rq