From 5745540f0ed4c09ed5e71855baa9035b6cc90a4d Mon Sep 17 00:00:00 2001 From: dohyeons Date: Fri, 17 Oct 2025 18:14:13 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=A8=ED=8A=B8=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/dashboard/QueryEditor.tsx | 119 +++++++----------- 1 file changed, 48 insertions(+), 71 deletions(-) diff --git a/frontend/components/admin/dashboard/QueryEditor.tsx b/frontend/components/admin/dashboard/QueryEditor.tsx index 81bee6ea..e83c9c9b 100644 --- a/frontend/components/admin/dashboard/QueryEditor.tsx +++ b/frontend/components/admin/dashboard/QueryEditor.tsx @@ -111,60 +111,44 @@ export function QueryEditor({ dataSource, onDataSourceChange, onQueryTest }: Que // 샘플 쿼리 삽입 const insertSampleQuery = useCallback((sampleType: string) => { const samples = { - comparison: `-- 제품별 월별 매출 비교 (다중 시리즈) --- 갤럭시(Galaxy) vs 아이폰(iPhone) 매출 비교 -SELECT - DATE_TRUNC('month', order_date) as month, - SUM(CASE WHEN product_category = '갤럭시' THEN amount ELSE 0 END) as galaxy_sales, - SUM(CASE WHEN product_category = '아이폰' THEN amount ELSE 0 END) as iphone_sales, - SUM(CASE WHEN product_category = '기타' THEN amount ELSE 0 END) as other_sales -FROM orders -WHERE order_date >= CURRENT_DATE - INTERVAL '12 months' -GROUP BY DATE_TRUNC('month', order_date) -ORDER BY month;`, + users: `SELECT + dept_name as 부서명, + COUNT(*) as 회원수 +FROM user_info +WHERE dept_name IS NOT NULL +GROUP BY dept_name +ORDER BY 회원수 DESC`, - sales: `-- 월별 매출 데이터 -SELECT - DATE_TRUNC('month', order_date) as month, - SUM(total_amount) as sales, - COUNT(*) as order_count -FROM orders -WHERE order_date >= CURRENT_DATE - INTERVAL '12 months' -GROUP BY DATE_TRUNC('month', order_date) -ORDER BY month;`, + dept: `SELECT + dept_code as 부서코드, + dept_name as 부서명, + location_name as 위치, + TO_CHAR(regdate, 'YYYY-MM-DD') as 등록일 +FROM dept_info +ORDER BY dept_code`, - users: `-- 사용자 가입 추이 -SELECT - DATE_TRUNC('week', created_at) as week, - COUNT(*) as new_users -FROM users -WHERE created_at >= CURRENT_DATE - INTERVAL '3 months' -GROUP BY DATE_TRUNC('week', created_at) -ORDER BY week;`, + usersByDate: `SELECT + DATE_TRUNC('month', regdate)::date as 월, + COUNT(*) as 신규사용자수 +FROM user_info +WHERE regdate >= CURRENT_DATE - INTERVAL '12 months' +GROUP BY DATE_TRUNC('month', regdate) +ORDER BY 월`, - products: `-- 상품별 판매량 -SELECT - product_name, - SUM(quantity) as total_sold, - SUM(quantity * price) as revenue -FROM order_items oi -JOIN products p ON oi.product_id = p.id -WHERE oi.created_at >= CURRENT_DATE - INTERVAL '1 month' -GROUP BY product_name -ORDER BY total_sold DESC -LIMIT 10;`, + usersByPosition: `SELECT + position_name as 직급, + COUNT(*) as 인원수 +FROM user_info +WHERE position_name IS NOT NULL +GROUP BY position_name +ORDER BY 인원수 DESC`, - regional: `-- 지역별 매출 비교 -SELECT - region as 지역, - SUM(CASE WHEN quarter = 'Q1' THEN sales ELSE 0 END) as Q1, - SUM(CASE WHEN quarter = 'Q2' THEN sales ELSE 0 END) as Q2, - SUM(CASE WHEN quarter = 'Q3' THEN sales ELSE 0 END) as Q3, - SUM(CASE WHEN quarter = 'Q4' THEN sales ELSE 0 END) as Q4 -FROM regional_sales -WHERE year = EXTRACT(YEAR FROM CURRENT_DATE) -GROUP BY region -ORDER BY Q4 DESC;`, + deptHierarchy: `SELECT + COALESCE(parent_dept_code, '최상위') as 상위부서코드, + COUNT(*) as 하위부서수 +FROM dept_info +GROUP BY parent_dept_code +ORDER BY 하위부서수 DESC`, }; setQuery(samples[sampleType as keyof typeof samples] || ""); @@ -197,22 +181,22 @@ ORDER BY Q4 DESC;`,
- - - - + + +
@@ -315,13 +299,6 @@ ORDER BY Q4 DESC;`, )} - - {/* 키보드 단축키 안내 */} - -
- 단축키: Ctrl+Enter (쿼리 실행), Ctrl+/ (주석 토글) -
-
); }