
sidebar.wechat

sidebar.feishu
sidebar.chooseYourWayToJoin

sidebar.scanToAddConsultant
Most enterprises face this dilemma: data exists in databases, but business personnel can't query it; technical personnel can query it, but they're too busy. Traditional BI tools have high learning costs and complex deployment, often bought and then left unused.
This article will teach you step-by-step how to build an enterprise-level AI data analysis system with AskTable in 1 hour, enabling business personnel to query data directly using natural language, without learning SQL or relying on technical teams.
After completing this tutorial, you will achieve:
✅ Connect to enterprise databases (MySQL/PostgreSQL/SQL Server, etc.) ✅ Configure business semantic layer so AI understands business terminology ✅ Query data using natural language, such as "Top 10 products by sales this month" ✅ Set up permission control to ensure data security ✅ Create reusable data analysis templates
Time required: 60 minutes Technical requirements: No programming foundation needed, just know how to use Excel Applicable scenarios: Small to medium enterprises, startup teams, department-level data analysis
Visit AskTable Official Website, click "Free Trial" to register.
Choose deployment method:
This tutorial uses Cloud SaaS as an example.
You need to prepare the following information (using MySQL as example):
db.example.com:3306sales_dbreadonly_userSecurity suggestions:
Don't have existing data? You can use our example database:
demo.asktable.com:3306ecommerce_demodemo_userdemo2026After logging into AskTable, go to the "Data Sources" page:
Connection name: Sales Database
Host address: db.example.com
Port: 3306
Database name: sales_db
Username: readonly_user
Password: ********
Common issues:
Q: Connection failed, prompt "Cannot connect to database" A: Check the following:
Q: My database is on an internal network and cannot be accessed externally A: There are two solutions:
After successful connection, AskTable will automatically read all tables in the database:
orders, products, customers)Tips:
Click on a table (such as orders) to view the table structure:
Table name: orders (Orders Table)
Fields:
- order_id (int): Order ID
- user_id (int): User ID
- product_id (int): Product ID
- amount (decimal): Order amount
- status (varchar): Order status
- created_at (datetime): Creation time
- paid_at (datetime): Payment time
Table relationships: AskTable will automatically identify foreign key relationships, such as:
orders.user_id → customers.user_idorders.product_id → products.product_idIf automatic identification is inaccurate, you can manually configure table relationships.
The business semantic layer is the key to enabling AI to understand business language. We need to tell AI:
Go to the "Semantic Layer" page and click "Add Metric":
Example 1: Sales (GMV)
Metric name: Sales
English name: GMV
Description: Total amount of paid orders
Calculation method: Aggregation
Aggregation function: SUM
Field: orders.amount
Filter conditions:
- orders.status IN ('paid', 'completed')
Unit: Yuan
Synonyms:
- Revenue
- Transaction Volume
- Total Sales
Example 2: Order Volume
Metric name: Order Volume
English name: Order Count
Description: Total number of orders
Calculation method: Count
Aggregation function: COUNT
Field: orders.order_id
Filter conditions:
- orders.status != 'cancelled'
Synonyms:
- Order Count
- Number of Transactions
Example 3: Average Order Value
Metric name: Average Order Value
English name: AOV (Average Order Value)
Description: Average amount per order
Calculation method: Custom
SQL expression: SUM(amount) / COUNT(DISTINCT order_id)
Data table: orders
Filter conditions:
- orders.status IN ('paid', 'completed')
Unit: Yuan
Synonyms:
- Average Order Value
- Single Price Average
Example 4: Monthly Active Users (Complex Metric)
Metric name: Monthly Active Users
English name: MAU
Description: Number of deduplicated users with at least one login or purchase behavior in the past 30 days
Calculation method: Custom SQL
SQL definition: |
SELECT COUNT(DISTINCT user_id) as mau
FROM (
SELECT user_id, login_time as action_time
FROM user_login_logs
WHERE login_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
UNION
SELECT user_id, created_at as action_time
FROM orders
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
) AS active_users
Synonyms:
- Monthly Active
- MAU
Dimensions are perspectives for data analysis, used for grouping and filtering.
Example 1: Time Dimension
Dimension name: Order Date
Field: orders.created_at
Type: Date time
Supported granularities:
- Day: DATE(created_at)
- Week: YEARWEEK(created_at)
- Month: DATE_FORMAT(created_at, '%Y-%m')
- Year: YEAR(created_at)
Predefined time ranges:
- Today: created_at >= CURDATE()
- Yesterday: DATE(created_at) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
- This week: created_at >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
- This month: created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
- Last month: created_at >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
AND created_at < DATE_FORMAT(CURDATE(), '%Y-%m-01')
Example 2: Product Category Dimension
Dimension name: Product Category
Field: products.category
Type: Text
Hierarchy:
- Level 1 category: category_level1
- Level 2 category: category_level2
Possible values:
- Electronics
- Clothing
- Food
- Books
Example 3: User Region Dimension
Dimension name: User Region
Field: customers.region
Type: Text
Hierarchy:
- Major region: region_level1 (East China, North China, South China, etc.)
- Province: region_level2 (Beijing, Shanghai, Guangdong, etc.)
- City: region_level3 (Beijing City, Shanghai City, Guangzhou City, etc.)
Business rules encapsulate complex business logic.
Example: Valid Order Rule
Rule name: Valid Order
Description: Orders meeting the following conditions are considered valid
Conditions:
- status IN ('paid', 'completed', 'shipped')
- amount > 0
- user_id > 10000 # Exclude test users
- created_at >= '2024-01-01' # Only count data after 2024
SQL snippet: |
WHERE status IN ('paid', 'completed', 'shipped')
AND amount > 0
AND user_id > 10000
AND created_at >= '2024-01-01'
Application scenarios: All metrics involving order statistics automatically apply this rule to ensure consistent metrics.
After configuration, test it:
Question: "What is this month's sales?"
AI understands:
created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')SUM(amount), automatically applies "Valid Order" ruleGenerated SQL:
SELECT SUM(amount) as gmv
FROM orders
WHERE status IN ('paid', 'completed', 'shipped')
AND amount > 0
AND user_id > 10000
AND created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
Returned result:
This month's sales: ¥1,234,567
After configuring the semantic layer, you can start querying data using natural language.
Question 1: "What is yesterday's order volume?"
AI generates:
SELECT COUNT(*) as order_count
FROM orders
WHERE DATE(created_at) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
AND status != 'cancelled'
Question 2: "Daily sales this week"
AI generates:
SELECT
DATE(created_at) as date,
SUM(amount) as gmv
FROM orders
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
AND status IN ('paid', 'completed')
GROUP BY DATE(created_at)
ORDER BY date
Returned result: Automatically generates a line chart showing trends.
Question 3: "Compare this month's sales with last month"
AI generates:
SELECT
CASE
WHEN created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01') THEN 'This month'
ELSE 'Last month'
END as period,
SUM(amount) as gmv
FROM orders
WHERE created_at >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
AND status IN ('paid', 'completed')
GROUP BY period
Returned result:
This month: ¥1,234,567
Last month: ¥1,100,000
Growth rate: +12.2%
Question 4: "Sales proportion by product category"
AI generates:
SELECT
p.category,
SUM(o.amount) as gmv,
SUM(o.amount) / (SELECT SUM(amount) FROM orders WHERE status IN ('paid', 'completed')) * 100 as percentage
FROM orders o
JOIN products p ON o.product_id = p.product_id
WHERE o.status IN ('paid', 'completed')
GROUP BY p.category
ORDER BY gmv DESC
Returned result: Automatically generates a pie chart showing proportion by category.
Question 5: "Top 10 products by sales"
AI generates:
SELECT
p.product_name,
SUM(o.amount) as gmv
FROM orders o
JOIN products p ON o.product_id = p.product_id
WHERE o.status IN ('paid', 'completed')
GROUP BY p.product_id, p.product_name
ORDER BY gmv DESC
LIMIT 10
Round 1: "Sales by region this month" Return: East China ¥500K, North China ¥400K, South China ¥300K...
Round 2: "Only East China"
AI understands: Continue from previous query, add filter region = 'East China'
Round 3: "Group by city" AI understands: On the basis of East China, group by city
This multi-turn conversation capability makes data exploration smoother.
Data security is crucial, especially when involving customer information and financial data.
Go to the "Permission Management" page and create different roles:
Role 1: Sales Personnel
Role name: Sales Personnel
Permission scope:
Accessible data sources: Sales Database
Accessible tables:
- orders (can only see orders in their own region)
- customers (can only see customers in their own region)
- products (all visible)
Row-level permissions:
- orders: region = :user_region
- customers: region = :user_region
Column-level permissions:
- customers.phone: Masked display (138****5678)
- customers.id_card: Not visible
Role 2: Operations Personnel
Role name: Operations Personnel
Permission scope:
Accessible data sources: Sales Database
Accessible tables: All visible
Row-level permissions: No restrictions
Column-level permissions:
- customers.phone: Masked display
- customers.id_card: Masked display
Prohibited operations:
- Batch export customer data (single export limited to 100 records)
Role 3: Management
Role name: Management
Permission scope: All permissions
Row-level permissions: No restrictions
Column-level permissions: All visible
Allowed operations: All
Name: Zhang San
Email: zhangsan@company.com
Role: Sales Personnel
Custom attributes:
region: East China # Used for row-level permission filtering
Log in with "Zhang San's" account and ask: "This month's order volume"
Automatically applied permission filtering:
SELECT COUNT(*) as order_count
FROM orders
WHERE created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
AND region = 'East China' # Automatically added permission filter
Zhang San can only see East China region data and cannot see national data.
For sensitive fields, configure masking rules:
Phone number masking:
Field: customers.phone
Masking rule: CONCAT(LEFT(phone, 3), '****', RIGHT(phone, 4))
Example: 13812345678 → 138****5678
ID card masking:
Field: customers.id_card
Masking rule: CONCAT(LEFT(id_card, 6), '********', RIGHT(id_card, 4))
Example: 110101199001011234 → 110101********1234
Address masking:
Field: customers.address
Masking rule: CONCAT(SUBSTRING(address, 1, 10), '***')
Example: Beijing Chaoyang District Jianguomenwai Street No. 1 → Beijing Chaoyang District Jianguomen***
For commonly used queries, you can create templates for quick access.
Ask: "Sales and order volume by product category this month"
After successful query, click "Save as Template":
Template name: Monthly Product Category Analysis
Description: Statistics of sales and order volume by product category this month
Parameters:
- Time range: Optional (default this month)
- Product category: Optional (default all)
Sharing scope: Visible to entire company
Other users can find this template in the "Template Library":
Set up scheduled sending:
Report name: Daily Sales Brief
Query template: Monthly Product Category Analysis
Sending frequency: Daily at 9:00 AM
Recipients:
- zhangsan@company.com
- lisi@company.com
Sending method: Email
Format: PDF + Excel
Cause: Semantic layer configuration is incomplete, AI understanding has deviations.
Solution:
Example:
Example Queries:
Question: "New users this month"
Correct SQL: |
SELECT COUNT(DISTINCT user_id)
FROM users
WHERE DATE_FORMAT(created_at, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
Note: "New users" refers to users whose registration time is this month, not active users
Causes:
Solutions:
Problem: Data in the database updates in real-time, but AskTable query results have delays.
Solutions:
Problem: Order data is in MySQL, user behavior data is in ClickHouse, how to associate?
Solutions:
AskTable automatically selects chart types by default, but you can customize:
Query: "Sales by region"
Chart type: Map
Configuration:
Geographic field: region
Numeric field: gmv
Color scheme: Blue gradient
Export:
Share:
If you have development capabilities, you can integrate AskTable through API:
import requests
# Initiate query
response = requests.post(
'https://api.asktable.com/v1/query',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json={
'question': 'This month\'s sales',
'datasource_id': 'your_datasource_id'
}
)
result = response.json()
print(f"Sales: {result['data']['gmv']}")
Application scenarios:
Congratulations! You have completed building an enterprise-level AI data analysis system.
Review:
Total time: 60 minutes
Next steps:
Core value:
Actual effects (from real customers):
"We are a 50-person e-commerce team. Previously we had 10+ temporary data needs every day, and the data team was exhausted. After introducing AskTable, 70% of needs were completed by business personnel independently, and the data team was freed from 'data fetching' work to focus on higher-value analysis." — CTO of an e-commerce company
Start your data-driven journey:
Let data analysis return to its essence: Simple, fast, usable by everyone.
Related Resources:
sidebar.noProgrammingNeeded
sidebar.startFreeTrial