解决方案 »

  1.   

    先写个临时表#t,表中有三个字段age1,age2,age3,然后每个字段更新,最后查询临时表
      

  2.   

    CREATE TABLE  #t(age nvarchar(50) , count  nvarchar(50))
    insert into #t  (age) value('0-20')
    insert into #t  (age) value('20-30')
    insert into #t  (age) value('30-40')
    update a set count =(select count(age) from ageid  where age>=0 and age<=20) from #t a where a.age='0-20'
    update a set count =(select count(age) from ageid  where age>20 and age<=30)from #t a where a.age='20-30'
    update a set count =(select count(age) from ageid  where age >30 and age<40)from #t a where a.age='30-40'
    select  *  from #t这样分开写看的容易点
      

  3.   

    用饼图分析市场占有率
      private void showPic(float f, Brush B)
            {
                Graphics g = this.panel1.CreateGraphics(); //通过panel1控件创建一个Graphics对象
                if (TimeNum == 0.0f)
                {
                    g.FillPie(B, 0, 0, this.panel1.Width, this.panel1.Height, 0, f * 360);//绘制扇形
                }
                else
                {
                    g.FillPie(B, 0, 0, this.panel1.Width, this.panel1.Height, TimeNum, f * 360);
                }
                TimeNum += f * 360;
            }//CodeGo.net/
            private void Form1_Paint(object sender, PaintEventArgs e) //在Paint事件中绘制窗体
            {
                ht.Clear();
                Conn(); //连接数据库
                Random rnd = new Random(); //生成随机数
                using (cmd = new SqlCommand("select t_Name,sum(t_Num) as Num  from tb_product group by t_Name", con))
                {
                    Graphics g2 = this.panel2.CreateGraphics(); //通过panel2控件创建一个Graphics对象
                    SqlDataReader dr = cmd.ExecuteReader(); //创建SqlDataReader对象
                    while (dr.Read()) //读取数据
                    {
                        ht.Add(dr[0], Convert.ToInt32(dr[1])); //将数据添加到Hashtable中
                    }
                    float[] flo = new float[ht.Count];
                    int T = 0;
                    foreach (DictionaryEntry de in ht) //遍历Hashtable
                    {
                        flo[T] = Convert.ToSingle((Convert.ToDouble(de.Value) / SumNum).ToString().Substring(0, 6));
                        Brush Bru = new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)));
                        //绘制商品及百分比
                        g2.DrawString(de.Key + "  " + flo[T] * 100 + "%", new Font("Arial", 8, FontStyle.Regular), Bru, 7, 5 + T * 18);
                        showPic(flo[T], Bru); //调用showPic方法绘制饼型图
                        T++;
                    }
                }
            }