GSI




여기서 userList의 테이블과  calcInfo 의 테이블에 대해서 합치는 쿼리를 구성해 볼려구 한다.

두개의 테이블의 내용은 아래와 같다.
[userList]

[calcInfo]


두개의 테이블을 조인해야 하는데 문제는
calcInfo의 uid별 income, outcome을 sum을 해야 하는게 관건이였다.
쿼리는 잘 모르다 보니 이런 구문은 항상 아리송하다 ^^

아래는 결과 쿼리다.
select aa.uid, aa.puid, aa.gameCash, bb.income, bb.outcome from userList as aa
inner join
(select uid, sum(income) as income, sum(outcome) as outcome from calcInfo as bb group by uid)
bb on aa.uid = bb.uid

[출력화면]

Posted by gsi
:


Posted by gsi
:


기존에 집에서 서버를 돌리면서 장비를 3대를 돌리다 보니
전기세가 쩝.. 15만원이 나오더군요.

그래서 이번에 KSIDC에 서버 호스팅을 하게 되었다.
이제는 조금더 확장성 있는 서비스를 통해서
작업이 가능해 질거 같다.

[서버정보]
INTEL
SR-1530HSH Quad-Core System
Size : 1U
CPU : Xeon 3220 (Xeon Quad Core 2.4GHz / 8M / 1066Mhz)
Memory : DDR2 4G 5300U Samsung
HDD :  500GB SATA II , 최대 3TERA까지 가능
Network : Dual Intel® Gigabit Ethernet connections

Posted by gsi
:


declare @idx int
declare @account varchar(20)
declare @nickname varchar(20)
declare @account2 varchar(20)
declare @nickname2 varchar(20)

set @idx = 0
set @account = 'test'
set @nickname = 'Dummy'

while (1=1)
begin
 if @idx > 9999 break;
 set @account2 = @account + convert(varchar(4), @idx)
 set @nickname2 = @nickname + convert(varchar(4), @idx)
 print @idx
 print @account2 + @nickname2
 INSERT INTO [NDT].[dbo].[USERACCOUNT]
           ([ACCOUNT]
           ,[PASSWORD]
           ,[NICKNAME]
           ,[MONEY]
           ,[LOGINSTATE])
     VALUES
           (@account2
           ,'1'
           ,@nickname2
           ,0
           ,0)
 set @idx = @idx + 1
end

Posted by gsi
:


-- Join.aspx--
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Join.aspx.cs" Inherits="AjaxTest.Join" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style type="text/css">
        body{ font-size:10pt; font-family:돋움;}
        .panel{position:fixed; float:right;}
    </style>
    <script type="text/javascript" language="javascript">
        var xmlHttp;
       
        function createXMLHttpRequest()
        {
            if (window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            }
            else if (window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
       
        function idCheck()
        {
            var id = document.getElementById("txtId").value;
            var hid = document.getElementById("HiddenField1");
            createXMLHttpRequest();
            xmlHttp.open("get", "id_check.aspx?id=" + id, false);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttp.send(null);
            if (xmlHttp.readyState == 4) //받을 문자가 있을떄
            {
                if (xmlHttp.status == 200) //정상적으로 받았을때
                {
                    var returnvalue = xmlHttp.responseText;  // 받는 문
                    if(returnvalue == "0")
                    {
                        alert('사용가능합니다.');
                        hid.value = 1;   //1번 퀴즈의 닶                        
                    }
                    else
                    {
                        alert('존재하는 아이디 입니다.');
                        id = "";
                    }
                }
                else
                {
                    alert('error..');
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>이름</td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>주민등록번호</td>
                    <td>
                        <asp:TextBox ID="txtRegNo1" runat="server"></asp:TextBox>-<asp:TextBox ID="txtRegNo2" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>ID</td>
                    <td>
                        <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
                        <input type="button" value="중복확인" onclick="idCheck()" />
                    </td>
                </tr>
                <tr>
                    <td>비밀번호</td>
                    <td>
                        <asp:TextBox ID="txtPwd1" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>비밀번호확인</td>
                    <td>
                        <asp:TextBox ID="txtPwd2" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>주소</td>
                    <td>
                        <asp:TextBox ID="txtAddr1" runat="server" Width="237px"></asp:TextBox>
                        <asp:Button ID="btnAddr" runat="server" Text="주소찾기" />
                    </td>
                </tr>
                <tr>
                    <td>상세주소</td>
                    <td>
                        <asp:TextBox ID="txtAddr2" runat="server" Width="316px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>우편번호</td>
                    <td>
                        <asp:TextBox ID="txtZip1" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtZip2" runat="server" Width="49px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>전화번호</td>
                    <td>
                        <asp:TextBox ID="txtPhone1" runat="server" Width="49px"></asp:TextBox>
                        -&nbsp;
                        <asp:TextBox ID="txtPhone2" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtPhone3" runat="server" Width="49px"></asp:TextBox>&nbsp;
                    </td>
                </tr>
                <tr>
                    <td>핸드폰</td>
                    <td>
                        <asp:TextBox ID="txtCell1" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtCell2" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtCell3" runat="server" Width="49px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>이메일</td>
                    <td>
                        <asp:TextBox ID="txtEmail" runat="server" Width="249px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>메일 수신여부</td>
                    <td>수신하시겠습니까?<asp:CheckBoxList ID="CKYN" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" >
                        <asp:ListItem Text="YES" Value="1"></asp:ListItem>
                        <asp:ListItem Text="NO" Value="0"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:Button ID="btnJoin" runat="server" Text="가입하기" OnClick="btnJoin_Click" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="eee" style="display:none;">
            <p style="color:Red; font-weight:bold;" id="sssss">중복아이디 확인을 해주세요.</p>
        </div>
        <asp:HiddenField ID="HiddenField1" runat="server" Value="0" />
    </form>
</body>
</html>

-- Join.aspx.cs--
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace AjaxTest
{
    public partial class Join : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnJoin_Click(object sender, EventArgs e)
        {
            if (Request.Form["HiddenField1"].ToString() == "1")
            {
                string strSql = "exec UserJoin ";
                strSql += "'" + txtId.Text + "','" + txtPwd1.Text + "','" + txtName.Text + "'," + txtRegNo1.Text;
                strSql += "," + txtRegNo2.Text + ",'" + txtAddr1.Text + "','" + txtAddr2.Text + "'," + txtZip1.Text;
                strSql += "," + txtZip2.Text + "," + txtPhone1.Text + "," + txtPhone2.Text + "," + txtPhone3.Text;
                strSql += "," + txtCell1.Text + "," + txtCell2.Text + "," + txtCell3.Text + ",'" + txtEmail.Text + "'," + CKYN.SelectedValue.ToString();

                SqlConnection objCon = new SqlConnection(Connected());
                SqlCommand objCmd = new SqlCommand(strSql, objCon);
                objCon.Open();
                objCmd.ExecuteNonQuery();
                objCon.Close();
            }
            else
            {
                String csname1 = "IDCHECK";
                Type cstype = this.GetType();
                ClientScriptManager cs = Page.ClientScript;

                if (!cs.IsStartupScriptRegistered(cstype, csname1))
                {
                    String cstext1 = "document.getElementById('eee').style.display = '';";
                    cs.RegisterStartupScript(cstype, csname1, cstext1, true);
                }
            }
        }

        public string Connected()
        {
            ConnectionStringSettings settings;
            settings = System.Configuration.ConfigurationManager.ConnectionStrings["tomochanwebConnectionString"];
            string connectionString = settings.ConnectionString;
            return connectionString;
        }
    }
}

-- id_check.aspx--
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="id_check.aspx.cs" Inherits="AjaxTest.id_check" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
</body>
</html>

-- id_hceck.aspx.cs--
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace AjaxTest
{
    public partial class id_check : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //리턴할 값을 넣을 변수 선언
            string strRturn = "0";
            //쿼리스트링 값 받는 변수 선언 및 할당
            string strID = Request.QueryString["id"].ToString();
            // 아이디 체크를 위한 쿼리
            string strSql = "SELECT Count(*) FROM user_info where uid = '" + strID + "'";
            //콘넥션 개체 생성
            SqlConnection objCon = new SqlConnection(Connected());
            SqlCommand objCmd = new SqlCommand(strSql, objCon);
            objCon.Open();
            SqlDataReader reader = objCmd.ExecuteReader();
            while (reader.Read())
            {
                //데이터 리드를 통한 쿼리값을 받음
                strRturn = reader[0].ToString();
            }
            reader.Close();
            objCon.Close();

            // utf-8로 인코딩하여 join.aspx페이지에 strRturn값을 보내줌.
            Response.ContentType = "UTF-8";
            Response.Write(strRturn);
            Response.Flush();
            Response.End();
        }
       
        public string Connected()
        {
            ConnectionStringSettings settings;
            settings = System.Configuration.ConfigurationManager.ConnectionStrings["tomochanwebConnectionString"];
            string connectionString = settings.ConnectionString;
            return connectionString;
        }
    }
}

Posted by gsi
: