#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <netinet/in.h>
#include <string.h>

#define MAXLINE 99999
#define MAX_SOCK 64

int getmax(int);
void disconnect_client(int); /* 채팅 탈퇴 처리 함수 */
void my_signal(int signo); /* 새로운 시그널 처리 함수 선언 */

int maxfdp1;            /* 최대 소켓번호+1 */
int num_chat = 0;       /* 채팅 참가자 수 */
int ____main_socket;                  /* 초기 소켓 */
int ____client_socket[MAX_SOCK]; /* 채팅에 참가자 소켓번호 목록 */

int main(int argc, char *argv[]) 
{
char rline[MAXLINE+1];
int i, j, kk;
int recv_len;
int client_fd, clilen;

int recv_len_sum=0;
int recv_seq_sum=0;
int recv_divide;


fd_set read_fds; /* 일기 감지할 소켓번호 구조체 */
struct sockaddr_in client_addr, server_addr;

if (argc != 2) {
printf("Usage: %s port\n", argv[0]);
exit(0);
}

/* 초기소켓 생성 */
if ((____main_socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
printf("Server: Can't open stream socket.");
exit(0);
}

/* server_addr 구조체의 내용 세팅 */
bzero((char *)&server_addr, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
server_addr.sin_port = htons(atoi(argv[1]));

if (bind(____main_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
printf("Server: Can't bind local address.\n");
exit(0);
}

if (signal(SIGINT, my_signal) == SIG_ERR) { /* Ctrl+C */
printf("Server: signal(SIGINT) error\n");
exit(0);
}
if (signal(SIGTERM, my_signal) == SIG_ERR) { /* software termination */
printf("Server: signal(SIGTERM) error\n");
exit(0);
}
if (signal(SIGQUIT, my_signal) == SIG_ERR) { /* Ctrl+\ */
printf("Server: signal(SIGQUIT) error\n");
exit(0);
}


/* 클라이언트로부터 연결요청을 기다림 */
listen(____main_socket, 5); /* backlog = 5 */

maxfdp1 = ____main_socket + 1; /* 최대 소켓번호+1 */

while (1) 
{
FD_ZERO(&read_fds);
FD_SET(____main_socket, &read_fds);
for (kk=0; kk < num_chat; kk++)
{
    FD_SET(____client_socket[kk], &read_fds);
}

maxfdp1 = getmax(____main_socket) + 1; /* maxfdp1 재 계산 */

if (select(maxfdp1, &read_fds, (fd_set *)0, (fd_set *)0, (struct timeval *)0) < 0) {
printf("Server: select error <= 0\n");
break;
}

if (FD_ISSET(____main_socket, &read_fds)) 
{
clilen = sizeof(client_addr);
client_fd = accept(____main_socket, (struct sockaddr *)&client_addr, &clilen);
if (client_fd == -1) 
{
    printf("Server: accept error\n");
    break;
    }

    ____client_socket[num_chat] = client_fd;
    num_chat++;
}

for (kk=0; kk < num_chat; kk++) 
{
if (FD_ISSET(____client_socket[kk], &read_fds)) 
{
if ((recv_len = recv(____client_socket[kk], rline, MAXLINE, 0)) <= 0) 
{
disconnect_client(kk); /* abrupt exit */
continue;
}
rline[recv_len] = '\0';

            recv_divide = recv_len / getfromframeid(rline, recv_len);
recv_seq_sum++;
recv_len_sum = recv_len_sum + recv_divide;

printf("SESSION SEQ[%07d]/RECV LENGTH[%07d]/DIVIDE[%07d]/REAL SUM[%07d]/SEQ SUM[%07d]\n", 
                                        kk+1, recv_len,
recv_divide, recv_len_sum, recv_seq_sum);
}
}
} /* while */
my_signal(SIGIO);
}

/* 채팅 탈퇴 처리 */
void disconnect_client(int i) {
struct sockaddr_in client_addr;

close(____client_socket[i]);
if (i != num_chat-1)
____client_socket[i] = ____client_socket[num_chat-1];
num_chat--;

printf("[function]disconnect_client>>[%d]\n", num_chat);
}

/* ____client_socket[] 내의 최대 소켓번호 얻기(초기치는 k) */
int getmax(int k) {
int max = k;
int r;
for (r=0; r < num_chat; r++)
if (____client_socket[r] > max)
max = ____client_socket[r];
return max;
}

/* 시그널 처리 함수 정의 */
void my_signal(int signo) {
int i;

signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
signal(SIGQUIT, SIG_IGN);

/* 모든 열려있는 소켓을 닫는다 */
close(____main_socket);
for (i=0; i < num_chat; i++)
close(____client_socket[i]);

exit(0);
}

int getfromframeid(char *tmp, int len)
{
int kk=0;

if(memcmp(tmp, "A0011", 5) == 0) kk=800;

return kk;
}


extern char design[6][2+1];
extern int ____hexa[MAPY][MAPX];
extern int hexa[MAPY][MAPX];

 

 

 

void gotoxy(int x, int y)
{
    COORD Pos = {x - 1, y - 1};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}

void f_display_all(void)
{
    int i, k;

    for(i=0; i<MAPY; i++)
    {
        for(k=0; k<MAPX; k++)
        {
            if(hexa[i][k] == 10)
            {
                continue;
            }
            else if(hexa[i][k] == 0)
            {

                gotoxy(k * 2 + 1, i + 2);
                printf("□");

            }
            else
            {
               gotoxy(k * 2 + 1, i + 2);
               printf("%s", design[ hexa[i][k] ]);
            }
        }
    }


#if(1)
for(i=0; i<MAPY; i++)
    {
        for(k=0; k<MAPX; k++)
        {
____hexa[i][k] = hexa[i][k];
}
}
#endif
}

void f_display(int x, int y)
{
    int i, k;

#if(1)
    for(i=0; i<MAPY; i++)
    {
        for(k=0; k<MAPX; k++)
        {
            if(hexa[i][k] == 10)
            {
                continue;
            }
else if(hexa[i][k] == ____hexa[i][k]) continue;
            else if(hexa[i][k] == 0)
            {

                gotoxy(k * 2 + 1, i + 2);
                printf("□");

            }
            else
            {
               gotoxy(k * 2 + 1, i + 2);
               printf("%s", design[ hexa[i][k] ]);
            }
        }
    }
#endif

#if(1)
for(i=0; i<MAPY; i++)
    {
        for(k=0; k<MAPX; k++)
        {
____hexa[i][k] = hexa[i][k];
}
}
#endif
}

#if(1)
    if(____type==0)  //처음 한번은 전체출력으로 하고, 다음부터는 변한부분만 출력하도록 한다.
{
        for(i=0; i<MAPY; i++)
{
            for(k=0; k<MAPX; k++)
                {
if(hexa[i][k] == 10)
{
continue;
}
else if(hexa[i][k] == 0)
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, "□", 2);
}
else
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, design[ hexa[i][k] ], 2);
}
}
}
____type=1;
}
else
{
for(i=0; i<MAPY; i++)
{
for(k=0; k<MAPX; k++)
{
if(hexa[i][k] == ____hexa[i][k]) continue;
else if(hexa[i][k] == 0)
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, "□", 2);
}
else
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, design[ hexa[i][k] ], 2);
}
}
}
}
#endif

#include <time.h>
struct tm *localtime_r(const time_t *timep, struct tm *result);



----DESCRIPTION
localtime_r 함수는 time_t type의 초단위의 시간을 지역시간(locale정보)의 struct tm type으로 변환하는 함수입니다.
localtime()함수가 변환된 결과를 local static변수에 저장하는것과 달리 localtime_r()함수는 data를 변환한 결과값을
result에 저장하기때문에 multi-thread에서도 안전한 thread-safe함수입니다.





#include <time.h>
#include <stdio.h>

struct tm *localtime_r(const time_t *timep, struct tm *result);

int main(int argc, char **argv[])
{
    time_t t;
    struct tm lt;
 
    if((t=time(NULL))==-1) {
        printf("time() call error\n");
        return -1;
    }
    if(localtime_r(&t, &lt)==NULL) {
        printf("localtime_r() call error\n");
        return -1;
    }
    printf("NOW TIME:%04d-%02d-%02d %02d:%02d:%02d\n",
    lt.tm_year + 1900,
    lt.tm_mon + 1,
    lt.tm_mday,
    lt.tm_hour,
    lt.tm_min,
    lt.tm_sec);
 
    return 0;

/* 

 * printf에서 자주사용되고, 유용한 *에 대해서 알아본다.

 * printf에서 자주사용되고, 유용한 *에 대해서 알아본다.

 * printf에서 자주사용되고, 유용한 *에 대해서 알아본다.

 */

 

#include <stdio.h>

 

struct TESTSCORE_ST

{

    char Number[5];

    char Name[20];

char KorScore[10];

char EngScore[10];

char MathScore[10];

};

 

//구조체변수 초기화및 데이타 세팅하기

struct TESTSCORE_ST score[7] = {

{"1001", "Park", "90.2", "65.43", "56.99"},

{"1002", "Lee", "90.2", "65.43", "56.99"},

{"1003", "Choi", "90.2", "65.43", "56.99"},

{"1004", "Jung", "90.2", "65.43", "56.99"},

{"1005", "Son", "90.2", "65.43", "56.99"},

{"1006", "Nam", "90.2", "65.43", "56.99"},

{"1007", "Kim", "90.2", "65.43", "56.99"} };

 

int main(void)

{

    int kk;

 

for(kk=0; kk<7; kk++)

{

        //LEFT정렬,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

        printf("[%-*s]"

           "[%-*s]"

          "[%-*s]"

   "[%-*s]"

   "[%-*s]",

      sizeof(score[kk].Number), score[kk].Number,

      sizeof(score[kk].Name), score[kk].Name,

      sizeof(score[kk].KorScore), score[kk].KorScore,

      sizeof(score[kk].EngScore), score[kk].EngScore,

      sizeof(score[kk].MathScore), score[kk].MathScore);

printf("\n");

        //RIGHT정렬,,ㅡㅡㅡㅡㅡㅡㅡㅡ

printf("[%*s]"

        "[%*s]"

       "[%*s]"

       "[%*s]"

       "[%*s]",

      sizeof(score[kk].Number), score[kk].Number,

      sizeof(score[kk].Name), score[kk].Name,

      sizeof(score[kk].KorScore), score[kk].KorScore,

      sizeof(score[kk].EngScore), score[kk].EngScore,

      sizeof(score[kk].MathScore), score[kk].MathScore);

printf("\n");

printf("[%s]"

           "[%s]"

   "[%s]"

   "[%s]"

          "[%s]",

      score[kk].Number,

      score[kk].Name,

      score[kk].KorScore,

      score[kk].EngScore,

      score[kk].MathScore);

        printf("\n");

}

return 0;

}

 

/*RESULT

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

 

[1001 ][Park                ][90.2      ][65.43     ][56.99     ]

[ 1001][                Park][      90.2][     65.43][     56.99]

[1001][Park][90.2][65.43][56.99]

[1002 ][Lee                 ][90.2      ][65.43     ][56.99     ]

[ 1002][                 Lee][      90.2][     65.43][     56.99]

[1002][Lee][90.2][65.43][56.99]

[1003 ][Choi                ][90.2      ][65.43     ][56.99     ]

[ 1003][                Choi][      90.2][     65.43][     56.99]

[1003][Choi][90.2][65.43][56.99]

[1004 ][Jung                ][90.2      ][65.43     ][56.99     ]

[ 1004][                Jung][      90.2][     65.43][     56.99]

[1004][Jung][90.2][65.43][56.99]

[1005 ][Son                 ][90.2      ][65.43     ][56.99     ]

[ 1005][                 Son][      90.2][     65.43][     56.99]

[1005][Son][90.2][65.43][56.99]

[1006 ][Nam                 ][90.2      ][65.43     ][56.99     ]

[ 1006][                 Nam][      90.2][     65.43][     56.99]

[1006][Nam][90.2][65.43][56.99]

[1007 ][Kim                 ][90.2      ][65.43     ][56.99     ]

[ 1007][                 Kim][      90.2][     65.43][     56.99]

[1007][Kim][90.2][65.43][56.99]

----------------------------------------------------------------------------*/

 

 

 

   

mysql> select @r:=@r+1 As rowNum, T2.t_regtime,T2.t_cnt from DUMMY T1, (select substr(regtime,1,17) as t_regtime, count(1) as t_cnt from RB_OCUS_POS_TEST2 group by substr(regtime,1,17)) T2, (Select @r:=0)r;
+--------+-------------------+-------+
| rowNum | t_regtime         | t_cnt |
+--------+-------------------+-------+
|      1 | 20190829 12:42:03 |   669 |
|      2 | 20190829 12:42:04 |  3021 |
|      3 | 20190829 12:42:05 |  5429 |
|      4 | 20190829 12:42:06 |  5005 |
|      5 | 20190829 12:42:07 |  3661 |
|      6 | 20190829 12:42:08 |  3310 |
|      7 | 20190829 12:42:09 |  2807 |
|      8 | 20190829 12:42:10 |  3950 |
|      9 | 20190829 12:42:11 |  4715 |
|     10 | 20190829 12:42:12 |  5130 |
|     11 | 20190829 12:42:13 |  4318 |
|     12 | 20190829 12:42:14 |  2918 |
|     13 | 20190829 12:42:15 |  2980 |
|     14 | 20190829 12:42:16 |  4156 |
|     15 | 20190829 12:42:17 |  5870 |
|     16 | 20190829 12:42:18 |  5236 |
|     17 | 20190829 12:42:19 |  5546 |
|     18 | 20190829 12:42:20 |  5367 |
|     19 | 20190829 12:42:21 |  3181 |
|     20 | 20190829 12:42:22 |  2807 |
|     21 | 20190829 12:42:23 |  2554 |
|     22 | 20190829 12:42:24 |  1379 |
|     23 | 20190829 12:42:25 |  4924 |
|     24 | 20190829 12:42:26 |  4724 |
|     25 | 20190829 12:42:27 |  5641 |
|     26 | 20190829 12:42:28 |  5661 |
|     27 | 20190829 12:42:29 |  3936 |
|     28 | 20190829 12:42:30 |  3557 |
|     29 | 20190829 12:42:31 |  4186 |
|     30 | 20190829 12:42:32 |  4821 |
|     31 | 20190829 12:42:33 |  4621 |
|     32 | 20190829 12:42:34 |  4697 |
|     33 | 20190829 12:42:35 |  3264 |
|     34 | 20190829 12:42:36 |  3706 |
|     35 | 20190829 12:42:37 |  2423 |
|     36 | 20190829 12:42:38 |  2043 |
|     37 | 20190829 12:42:39 |  4207 |
|     38 | 20190829 12:42:40 |  3524 |
|     39 | 20190829 12:42:41 |  4656 |
|     40 | 20190829 12:42:42 |  3582 |
|     41 | 20190829 12:42:43 |  2995 |
|     42 | 20190829 12:42:44 |   120 |
+--------+-------------------+-------+
42 rows in set (0.25 sec)

mysql>


 

다음과 같은 테이블이 존재한다. (테이블명 : ISS_HH)

SEQ_NO(PK) USER_ID INFO1 INFO2
1 10001 HH KK
2 10002 HH KK
3 10003 HH KK
4 10004 HH KK
5 10005 HH KK
6 10006 HH KK
7 10007 HH KK
8 10008 HH KK
9 10009 HH KK
10 10010 HH KK
11 10011 HH KK
12 10012 HH KK

 

위의 SEQ_NO를 1씩 증가시키기 위해서는 보통 아래와 같은 SQL을 생각하기 쉽다.

 

SQL>UPDATE ISS_HH SET SEQ_NO = SEQ_NO + 1 WHERE USER_ID > 10000

 

그러나 위를 실행하면, DUPLICATE ERROR가 발생한다. 이유는 멀까? 

 

PK인 SEQ_NO에 UPDATE시에 데이타가 중복으로 발생하게 된다. 즉 이런 경우는 가장큰 SEQ_NO를 증가시키는것이 일반적이다.

 

>>>>>>>>>OK QUERY

SQL>UPDATE ISS_HH SET SEQ_NO = SEQ_NO + 1 WHERE USER_ID > 10000 ORDER BY SEQ_NO DESC

 

-1 을 할경우는 반대로 생각하면 된다.

SQL>UPDATE ISS_HH SET SEQ_NO = SEQ_NO -1 WHERE USER_ID > 10000 ORDER BY SEQ_NO ASC

 

 

비고) 한번에 처리하지 않고, 하나씩 처리하는 프로그램으로 작성해보라,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

비고) 한번에 처리하지 않고, 하나씩 처리하는 프로그램으로 작성해보라,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

비고) 한번에 처리하지 않고, 하나씩 처리하는 프로그램으로 작성해보라,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

비고) 한번에 처리하지 않고, 하나씩 처리하는 프로그램으로 작성해보라,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

 

 

 

1. RB_OCUS_POS_TEST2테이블에 200,00개의 데이타를 넣는다.

2. 1초에 3,000개 이상의 데이타가 들어가는 횟수를 알고 싶다면?

3. 아래는 위의 문제를 구하기 위해서 구성한 쿼리이다.

 

 

mysql> show create table RB_OCUS_POS_TEST2;
+-------------------+-----------------------------------
| Table             | Create

+-------------------+-----------------------------------
| RB_OCUS_POS_TEST2 | CREATE TABLE `RB_OCUS_POS_TEST2` (
  `seqno` int(11) NOT NULL,
  `account_no` varchar(10) NOT NULL,
  `stock_symbol` varchar(20) NOT NULL,
  `start_volume` varchar(10) DEFAULT NULL,
  `start_amount` varchar(13) DEFAULT NULL,
  `start_price` varchar(13) DEFAULT NULL,
  `stock_type` varchar(2) DEFAULT NULL,
  `trustee_id` varchar(2) DEFAULT NULL,
  `regtime` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`seqno`,`account_no`,`stock_symbol`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------------------+-----------------------------------
1 row in set (0.00 sec)

mysql>

mysql> desc RB_OCUS_POS_TEST2;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| seqno        | int(11)     | NO   | PRI | NULL    |       |
| account_no   | varchar(10) | NO   | PRI | NULL    |       |
| stock_symbol | varchar(20) | NO   | PRI | NULL    |       |
| start_volume | varchar(10) | YES  |     | NULL    |       |
| start_amount | varchar(13) | YES  |     | NULL    |       |
| start_price  | varchar(13) | YES  |     | NULL    |       |
| stock_type   | varchar(2)  | YES  |     | NULL    |       |
| trustee_id   | varchar(2)  | YES  |     | NULL    |       |
| regtime      | varchar(30) | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

mysql>

mysql> select * from RB_OCUS_POS_TEST2 limit 10;
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+------------------------+
| seqno | account_no | stock_symbol         | start_volume | start_amount  | start_price   | stock_type | trustee_id | regtime                |
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+------------------------+
|     1 | 0016100    | BBL                  | 0000001500   | 0000266962.22 | 000177.974813 | 02         |            | 20190828 11:19:25(140) |
|     2 | 0016100    | BPP                  | 0000002000   | 0000042000.00 | 000021.000000 | 02         |            | 20190828 11:19:25(141) |
|     3 | 0016100    | CK                   | 0000015375   | 0000296816.51 | 000019.305139 | 02         |            | 20190828 11:19:25(142) |
|     4 | 0016100    | IEC                  | 0012286603   | 0000308909.54 | 000000.025142 | 02         |            | 20190828 11:19:25(142) |
|     5 | 0016100    | IVL                  | 0000011769   | 0000309729.03 | 000026.317362 | 02         |            | 20190828 11:19:25(142) |
|     6 | 0016100    | KTB                  | 0000005000   | 0000103785.51 | 000020.757102 | 02         |            | 20190828 11:19:25(142) |
|     7 | 0055920    | ASAP                 | 0000001000   | 0000003106.87 | 000003.106870 | 02         |            | 20190828 11:19:25(142) |
|     8 | 0055920    | BCP                  | 0000001000   | 0000033574.22 | 000033.574220 | 02         |            | 20190828 11:19:25(142) |
|     9 | 0055920    | CBG                  | 0000000800   | 0000042844.70 | 000053.555875 | 02         |            | 20190828 11:19:25(143) |
|    10 | 0055920    | CHAYO                | 0000002000   | 0000008739.30 | 000004.369650 | 02         |            | 20190828 11:19:25(143) |
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+------------------------+
10 rows in set (0.00 sec)

mysql>

mysql> select T2.t_cnt from DUMMY T1, (select substr(regtime,1,17) as t_regtime, count(1) as t_cnt from RB_OCUS_POS_TEST2 group by substr(regtime,1,17)) T2 limit 10;
+-------+
| t_cnt |
+-------+
|  2149 |
|  2556 |
|  3462 |
|  2635 |
|  2780 |
|  3051 |
|  2450 |
|  2310 |
|  2695 |
|  2716 |
+-------+
10 rows in set (0.22 sec)

mysql> 
mysql> select T2.t_cnt from DUMMY T1, (select substr(regtime,1,17) as t_regtime, count(1) as t_cnt from RB_OCUS_POS_TEST2 group by substr(regtime,1,17)) T2 where T2.t_cnt > 3000;
+-------+
| t_cnt |
+-------+
|  3462 |
|  3051 |
|  3192 |
|  3761 |
|  3085 |
|  3418 |
|  3341 |
|  3066 |
|  3353 |
|  3287 |
|  3037 |
+-------+
11 rows in set (0.23 sec)

mysql>

mysql> select * from DUMMY;
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+
| seqno | account_no | stock_symbol         | start_volume | start_amount  | start_price   | stock_type | trustee_id |
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+
|     1 | 0016100    | BANPU                | 0000045000   | 0000645569.57 | 000014.345990 | 02         |            |
+-------+------------+----------------------+--------------+---------------+---------------+------------+------------+
1 row in set (0.00 sec)

mysql>

 

mysql> select T2.t_regtime,T2.t_cnt from DUMMY T1, (select substr(regtime,1,17) as t_regtime, count(1) as t_cnt from RB_OCUS_POS_TEST2 group by substr(regtime,1,17)) T2 where T2.t_cnt > 3000;
+-------------------+-------+
| t_regtime         | t_cnt |
+-------------------+-------+
| 20190828 11:19:27 |  3462 |
| 20190828 11:19:30 |  3051 |
| 20190828 11:19:38 |  3192 |
| 20190828 11:19:46 |  3761 |
| 20190828 11:19:47 |  3085 |
| 20190828 11:19:55 |  3418 |
| 20190828 11:20:00 |  3341 |
| 20190828 11:20:03 |  3066 |
| 20190828 11:20:12 |  3353 |
| 20190828 11:20:15 |  3287 |
| 20190828 11:20:20 |  3037 |
+-------------------+-------+
11 rows in set (0.19 sec)

mysql>  

 

mysql> select T2.t_regtime,T2.t_cnt from DUMMY T1, (select substr(regtime,1,17) as t_regtime, count(1) as t_cnt from RB_OCUS_POS_TEST2 group by substr(regtime,1,17)) T2 where T2.t_cnt > 3000 order by T2.t_cnt desc;
+-------------------+-------+
| t_regtime         | t_cnt |
+-------------------+-------+
| 20190828 11:19:46 |  3761 |
| 20190828 11:19:27 |  3462 |
| 20190828 11:19:55 |  3418 |
| 20190828 11:20:12 |  3353 |
| 20190828 11:20:00 |  3341 |
| 20190828 11:20:15 |  3287 |
| 20190828 11:19:38 |  3192 |
| 20190828 11:19:47 |  3085 |
| 20190828 11:20:03 |  3066 |
| 20190828 11:19:30 |  3051 |
| 20190828 11:20:20 |  3037 |
+-------------------+-------+
11 rows in set (0.00 sec)

mysql>

 

 

'데이타베이스 > MySQL' 카테고리의 다른 글

MySQL ROWNUM(select @r:=@r+1 As rowNum)  (0) 2019.10.31
TIP - SEQ증감  (0) 2019.10.31
FUNCTION 생성및 활용  (0) 2019.10.31
LINUX,프로그래밍을 통한 PROCEDURE 호출후 결과  (0) 2019.10.30
#LINUX,common.c(MySQL)  (0) 2019.10.30

+ Recent posts