Global It Leader!!



 
 

Mysql 입고테이블, 출고테이블을 이용한 재고 계산 쿼리

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 6,754회 작성일 11-07-29 22:31

본문


먼제 인덱스를 추가하고....
ALTER TABLE  `db명`.`입고테이블명` ADD INDEX  `in_mix1` (  `in_code` ,  `in_pumno` );
ALTER TABLE  `db명`.`출고테이블명` ADD INDEX  `pr_mix1` (  `pr_pumno` ,  `pr_code` );

1. 쿼리 1번

select in_code, max(in_pumno), max(in_dcno), sum(in_amt), sum(pr_amt), sum(in_amt) - sum(pr_amt), max(in_vendor) from (
SELECT in_code, in_pumno, in_dcno,  SUM( in_amount ) as in_amt, in_vendor, 0 as pr_amt
FROM in_table
WHERE in_pumno =  '2005173-2'
GROUP BY in_code
union all
SELECT pr_code as in_code, '' as in_pumno, '' as in_dcno, 0 as in_amt,'' as in_vendor, IFNULL( SUM( pr_amount ) , 0 ) AS pr_amt
FROM pr_table
WHERE pr_pumno =  '2005173-2'
GROUP BY pr_code
) a
group by in_code
order by in_code
LIMIT 30;

2. 쿼리 2번
pr_table 이 기준이라서 in_table에만 있는건 뺀 쿼리입니다.

select in_code, max(in_pumno), max(in_dcno), sum(in_amt), sum(pr_amt), sum(in_amt) - sum(pr_amt), max(in_vendor) from (
SELECT in_code, in_pumno, in_dcno,  SUM( in_amount ) as in_amt, in_vendor, 0 as pr_amt
FROM in_table
WHERE in_pumno =  '2005173-2'
GROUP BY in_code
union all
SELECT pr_code as in_code, '' as in_pumno, '' as in_dcno, 0 as in_amt,'' as in_vendor, IFNULL( SUM( pr_amount ) , 0 ) AS pr_amt
FROM pr_table
WHERE pr_pumno =  '2005173-2'
and pr_code in(select distinct(in_code) from in_table)
GROUP BY pr_code
) a
group by in_code
order by in_code
LIMIT 30;

3. 쿼리 3

select
  '2005173-2' as in_pumno,
  in_code,
  max(in_dcno),
  sum(in_amt),
  sum(pr_amt),
  sum(in_amt) - sum(pr_amt) as stock,
  max(in_vendor)
from (
  SELECT
    in_code,
    in_dcno,
    SUM(in_amount) as in_amt,
    in_vendor,
    0 as pr_amt
  FROM in_table
  WHERE in_pumno = '2005173-2'
  GROUP BY in_code
  union all
  SELECT
    pr_code as in_code,
    '' as in_dcno,
    0 as in_amt,
    '' as in_vendor,
    IFNULL( SUM( pr_amount ) , 0 ) AS pr_amt
  FROM pr_table
  WHERE pr_pumno = '2005173-2'
  and pr_code in(select distinct(in_code) from in_table)
  GROUP BY pr_code
) T
group by in_code
order by in_code

질의를 통해 sir.co.kr 회원이신 명랑폐인님이 작성한 쿼리입니다.

댓글목록

등록된 댓글이 없습니다.

전체 440
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
80 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5440 02-11
79 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5207 02-10
78 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5637 01-05
77 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5770 11-23
76 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7414 11-12
75 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6060 11-11
74 MsSql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5657 11-08
73 MsSql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9188 10-28
72 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6665 09-18
71 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6184 08-27
70 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6277 08-22
69 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8981 08-21
68 HTML no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7793 08-19
67 HTML no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6856 08-18
66 HTML no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6095 08-07
열람중 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6755 07-29
64 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6026 07-28
63 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6563 07-28
62 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8129 07-27
61 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7433 07-26