Files
stock/tushare/db/sql-query.sh
2025-03-17 11:08:13 +08:00

89 lines
8.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

select end_date,end_type, total_revenue, revenue, oper_cost, sell_exp, admin_exp, update_flag from t_ods_hs_finance_income where ts_code ='000002.SZ';
select ts_code, count(*) as cnt from t_ods_hs_finance_income GROUP BY ts_code ORDER BY ts_code asc;
## 半导体板块
SELECT ts_code, name, market FROM `t_ods_hs_base_list` WHERE industry='半导体';
##
select a.ts_code, b.name, a.end_date, a.update_flag, a.total_revenue, a.revenue, a.n_income_attr_p, a.total_cogs, a.oper_cost, a.sell_exp, a.admin_exp, a.fin_exp, a.rd_exp
from t_ods_hs_finance_income as a, t_ods_hs_base_list as b, t_meta_kechuang_chip as c
WHERE c.ts_code = b.ts_code AND a.ts_code = b.ts_code AND a.report_type = '1' AND a.end_type = '4' and a.update_flag=1
## 游戏行业的数据分析
select b.ts_code, c.name, b.end_date, b.roe, b.grossprofit_margin as '销售毛利率', b.netprofit_margin AS '销售净利率', b.profit_to_gr as '净利润/总收入', b.saleexp_to_gr as '销售成本/营收', b.adminexp_of_gr as '管理成本/营收', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '研发成本/营收', b.ebt_yoy as '利润增长率', b.tr_yoy AS '总营收增长率', b.netprofit_yoy as '归母利润增长率', b.dt_netprofit_yoy as '归母扣非利润增长率'
from t_meta_game as a, t_ods_hs_finance_indicator as b , t_ods_hs_base_list as c
WHERE a.ts_code = b.ts_code and a.ts_code = c.ts_code AND b.end_date like "%0630" and b.update_flag =1
ORDER BY b.ts_code desc, b.end_date ASC
# 游戏过滤出100亿市值以上的分析
select b.ts_code, c.name, b.end_date, b.roe, b.grossprofit_margin as '销售毛利率', b.netprofit_margin AS '销售净利率', b.saleexp_to_gr as '销售成本/营收', b.adminexp_of_gr as '管理成本/营收', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '研发成本/营收', b.ebt_yoy as '利润增长率', b.tr_yoy AS '总营收增长率'
from t_meta_game as a, t_ods_hs_finance_indicator as b , t_ods_hs_base_list as c, t_ods_hs_daily_basic as d
WHERE a.ts_code = b.ts_code and a.ts_code = c.ts_code AND a.ts_code=d.ts_code AND b.end_date like "%1231" and b.update_flag =1 AND d.trade_date='20220701' AND d.total_mv > 100*10000
ORDER BY b.ts_code desc, b.end_date ASC
## 科创芯片50亿以上的分析
select b.ts_code, c.name, b.end_date, format(d.total_mv/10000,2) as '当前市值', d.pe as '市盈率', d.ps as '市销率', b.roe, b.grossprofit_margin as '销售毛利率', b.netprofit_margin AS '销售净利率', b.saleexp_to_gr as '销售成本/营收', b.adminexp_of_gr as '管理成本/营收', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '研发成本/营收', b.ebt_yoy as '利润增长率', b.tr_yoy AS '总营收增长率'
from t_meta_kechuang_chip as a, t_ods_hs_finance_indicator as b , t_ods_hs_base_list as c, t_ods_hs_daily_basic as d
WHERE a.ts_code = b.ts_code and a.ts_code = c.ts_code AND a.ts_code=d.ts_code AND b.end_date like "%1231" and b.update_flag =1 AND d.trade_date='20220701' AND d.total_mv > 50*10000
ORDER BY b.ts_code desc, b.end_date ASC
## 半导体
select b.ts_code, c.name, b.end_date, format(d.total_mv/10000,2) as '当前市值', d.pe as '市盈率', d.ps as '市销率', b.roe, b.grossprofit_margin as '销售毛利率', b.netprofit_margin AS '销售净利率', b.saleexp_to_gr as '销售成本/营收', b.adminexp_of_gr as '管理成本/营收', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '研发成本/营收', b.netprofit_yoy as '利润增长率', b.tr_yoy AS '总营收增长率'
from t_ods_hs_base_list as a, t_ods_hs_finance_indicator as b , t_ods_hs_base_list as c, t_ods_hs_daily_basic as d
WHERE a.ts_code = b.ts_code and a.industry = '半导体' and a.ts_code = c.ts_code AND a.ts_code=d.ts_code AND b.end_date like "%1231" and b.update_flag =1 AND d.trade_date='20220701' AND d.total_mv > 50*10000
ORDER BY d.total_mv desc, b.end_date ASC
## 数据对比, indicator 表的管理费用/总营收数据不对。
SELECT a.ts_code, a.end_date, a.total_revenue, a.revenue, a.admin_exp, a.sell_exp, a.rd_exp, a.sell_exp/a.total_revenue*100 as '销售费用/总营收', a.admin_exp/a.total_revenue*100 as '管理费用/总营收', a.rd_exp/a.total_revenue*100 as '研发费用/总营收', b.saleexp_to_gr as '指标表.销售费用/营业总收入' , b.adminexp_of_gr as '指标表.管理费用/营业总收入', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '指标表.管理费用/营业总收入'
FROM t_ods_hs_finance_income as a , t_ods_hs_finance_indicator as b
WHERE a.ts_code= '688396.SH' AND a.end_date LIKE '20211231' and b.ts_code='688396.SH' AND b.update_flag = '1' and b.end_date='20211231'
## 影视
select b.ts_code, c.name, b.end_date, format(d.total_mv/10000,2) as '当前市值', d.pe as '市盈率', d.ps as '市销率', b.roe, b.grossprofit_margin as '销售毛利率', b.netprofit_margin AS '销售净利率', b.saleexp_to_gr as '销售成本/营收', b.adminexp_of_gr as '管理成本/营收', b.rd_exp/(b.gross_margin/b.grossprofit_margin) as '研发成本/营收', b.ebt_yoy as '利润增长率', b.tr_yoy AS '总营收增长率'
from t_meta_film as a, t_ods_hs_finance_indicator as b , t_ods_hs_base_list as c, t_ods_hs_daily_basic as d
WHERE a.ts_code = b.ts_code and a.ts_code = c.ts_code AND a.ts_code=d.ts_code AND b.end_date like "%1231" and b.update_flag =1 AND d.trade_date='20220701' AND d.total_mv > 30*10000
ORDER BY d.total_mv DESC, b.end_date ASC
## ROE 选股
SELECT a.ts_code, b.name, AVG(a.roe) as 'roe'
FROM t_ods_hs_finance_indicator AS a, t_ods_hs_base_list as b
WHERE a.ts_code = b.ts_code
GROUP BY ts_code
ORDER BY roe desc
## 华侨城
SELECT ts_code, end_date, total_revenue, total_cogs, (total_revenue - oper_cost)/total_revenue as '毛利率', n_income_attr_p, n_income_attr_p/total_revenue as '净利率'
FROM `t_ods_hs_finance_income`
WHERE ts_code='000069.SZ' AND end_type = '4' AND update_flag = 0;
SELECT ts_code, end_date, total_assets, total_liab, total_assets - total_liab as '净资产', total_hldr_eqy_exc_min_int , contract_liab, adv_receipts, inventories, fix_assets, (total_liab-contract_liab-adv_receipts)/(total_assets-contract_liab-adv_receipts) as '资产负债率', update_flag
FROM `t_ods_hs_finance_balance`
WHERE ts_code='000069.SZ' AND end_type = '4'
SELECT ts_code, end_date, total_assets, total_liab, total_assets - total_liab as '净资产', total_hldr_eqy_exc_min_int , contract_liab, adv_receipts, inventories, fix_assets, (total_liab-contract_liab-adv_receipts)/(total_assets-contract_liab-adv_receipts) as '资产负债率', inventories/total_assets as '存货/总资产', inventories/(total_assets - total_liab) as '存货/净资产', update_flag
FROM `t_ods_hs_finance_balance`
WHERE ts_code in('000069.SZ', '000002.SZ','600048.SH') AND end_type = '4'
SELECT ts_code, end_date, im_n_incr_cash_equ, c_inf_fr_operate_a, st_cash_out_act, n_cashflow_act, stot_inflows_inv_act, stot_out_inv_act, n_cashflow_inv_act, stot_cash_in_fnc_act, stot_cashout_fnc_act, n_cash_flows_fnc_act,update_flag
FROM `t_ods_hs_finance_cashflow`
WHERE ts_code='000069.SZ' AND end_type = '4'
## 按照毛利率和净利率选股
SELECT a.ts_code, b.name, a.end_date, a.total_revenue, a.revenue, a.oper_cost, format((a.revenue/a.total_revenue)*100, 2) as '主业营收比例', format((1- a.oper_cost/a.revenue)*100, 2) as '毛利率', format((total_profit /a. total_revenue)*100, 2) as '净利率', a.update_flag
FROM `t_ods_hs_finance_income` as a, t_ods_hs_base_list as b
WHERE a.ts_code = b.ts_code and a.end_type = '4'
ORDER BY a.ts_code asc, a.end_date asc
SELECT a.ts_code, b.name, a.end_date, format(a.grossprofit_margin,2) as '毛利率', format(a.netprofit_margin,2) as '净利率', format(a.tr_yoy,2) as '营收同比增长', format(a.ebt_yoy, 2) as '利润同比增长'
FROM `t_ods_hs_finance_indicator` as a, t_ods_hs_base_list as b
WHERE a.ts_code = b.ts_code and a.end_date like '%1231'
SELECT a.ts_code, b.name, format(c.total_mv/10000, 2), a.end_date, format(a.grossprofit_margin,2) as '毛利率', format(a.netprofit_margin,2) as '净利率', format(a.tr_yoy,2) as '营收同比增长', format(a.ebt_yoy, 2) as '利润同比增长'
FROM `t_ods_hs_finance_indicator` as a, t_ods_hs_base_list as b, t_ods_hs_daily_basic as c
WHERE a.ts_code = b.ts_code and c.ts_code =a.ts_code and a.end_date like '%1231'