{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2b46ea32-3e2e-466b-ac6a-9874336551af",
   "metadata": {},
   "outputs": [],
   "source": [
    "import dolphindb as ddb\n",
    "\n",
    "sess = ddb.session('localhost', 8848)\n",
    "sess.login('admin', '123456')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6cc64a77-a5ad-46b6-8204-b188ee308ad3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'partitionType': 5,\n",
       " 'partitionColumnType': 17,\n",
       " 'partitionColumnIndex': 0,\n",
       " 'chunkPath': None,\n",
       " 'colDefs':                           name typeString  typeInt comment\n",
       " 0                         code     SYMBOL       17        \n",
       " 1                report_period       DATE        6        \n",
       " 2               appear_at_date       DATE        6        \n",
       " 3         S_PROFITNOTICE_STYLE     STRING       18        \n",
       " 4     S_PROFITNOTICE_CHANGEMIN     DOUBLE       16        \n",
       " 5     S_PROFITNOTICE_CHANGEMAX     DOUBLE       16        \n",
       " 6  S_PROFITNOTICE_NETPROFITMIN     DOUBLE       16        \n",
       " 7  S_PROFITNOTICE_NETPROFITMAX     DOUBLE       16        \n",
       " 8        S_PROFITNOTICE_REASON     STRING       18        ,\n",
       " 'chunkGranularity': 'TABLE',\n",
       " 'partitionTypeName': 'HASH',\n",
       " 'keepDuplicates': 'ALL',\n",
       " 'engineType': 'TSDB',\n",
       " 'partitionColumnName': 'code',\n",
       " 'partitionSchema': 50,\n",
       " 'sortColumns': array(['code', 'report_period', 'appear_at_date'], dtype=object),\n",
       " 'partitionSites': None}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(\"tbl_ep = loadTable('dfs://pit_stock_ts', 'earnings_preannouncement')\")\n",
    "sess.run(\"schema(tbl_ep)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "39c05247-deac-4c49-a20d-e19e637c6081",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>report_period</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600543.SH</td>\n",
       "      <td>2021-12-31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>605499.SH</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>603729.SH</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>002058.SZ</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>601599.SH</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>600813.SH</td>\n",
       "      <td>2002-06-30</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>000689.SZ</td>\n",
       "      <td>2002-06-30</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>000653.SZ</td>\n",
       "      <td>2002-06-30</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>000658.SZ</td>\n",
       "      <td>2002-06-30</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>600853.SH</td>\n",
       "      <td>2001-12-31</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          code report_period  cnt\n",
       "0    600543.SH    2021-12-31    3\n",
       "1    605499.SH    2021-06-30    3\n",
       "2    603729.SH    2020-12-31    3\n",
       "3    002058.SZ    2020-12-31    3\n",
       "4    601599.SH    2020-12-31    3\n",
       "..         ...           ...  ...\n",
       "295  600813.SH    2002-06-30    4\n",
       "296  000689.SZ    2002-06-30    5\n",
       "297  000653.SZ    2002-06-30    4\n",
       "298  000658.SZ    2002-06-30    7\n",
       "299  600853.SH    2001-12-31    3\n",
       "\n",
       "[300 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(\"\"\"\n",
    "    select code, report_period, count(*) as cnt from tbl_ep group by code, report_period having count(*) > 2 order by report_period desc         \n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "74623941-5f6e-48fc-b2a0-7050ae6c6045",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>report_period</th>\n",
       "      <th>appear_at_date</th>\n",
       "      <th>S_PROFITNOTICE_STYLE</th>\n",
       "      <th>S_PROFITNOTICE_CHANGEMIN</th>\n",
       "      <th>S_PROFITNOTICE_CHANGEMAX</th>\n",
       "      <th>S_PROFITNOTICE_NETPROFITMIN</th>\n",
       "      <th>S_PROFITNOTICE_NETPROFITMAX</th>\n",
       "      <th>S_PROFITNOTICE_REASON</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600543.SH</td>\n",
       "      <td>2021-12-31</td>\n",
       "      <td>2021-10-30</td>\n",
       "      <td>预亏</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1-9月,公司累计营业收入增长39.61%,但较2019年同期仍有明显下滑,目前处于亏损状态...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>600543.SH</td>\n",
       "      <td>2021-12-31</td>\n",
       "      <td>2022-01-29</td>\n",
       "      <td>预亏</td>\n",
       "      <td>-4939.0</td>\n",
       "      <td>-4939.0</td>\n",
       "      <td>-9000.0</td>\n",
       "      <td>-9000.0</td>\n",
       "      <td>1、主营业务影响。受新冠肺炎疫情等因素影响,消费市场低迷,流通环节受限、下游需求收缩,公司葡...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>600543.SH</td>\n",
       "      <td>2021-12-31</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>预亏</td>\n",
       "      <td>-5408.0</td>\n",
       "      <td>-5408.0</td>\n",
       "      <td>-9872.0</td>\n",
       "      <td>-9872.0</td>\n",
       "      <td>公司财务部门将2021年度计提的固定资产减值准备4830万元,作非经常性损益处理,在审计时,...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        code report_period appear_at_date S_PROFITNOTICE_STYLE  \\\n",
       "0  600543.SH    2021-12-31     2021-10-30                   预亏   \n",
       "1  600543.SH    2021-12-31     2022-01-29                   预亏   \n",
       "2  600543.SH    2021-12-31     2022-03-31                   预亏   \n",
       "\n",
       "   S_PROFITNOTICE_CHANGEMIN  S_PROFITNOTICE_CHANGEMAX  \\\n",
       "0                       0.0                       0.0   \n",
       "1                   -4939.0                   -4939.0   \n",
       "2                   -5408.0                   -5408.0   \n",
       "\n",
       "   S_PROFITNOTICE_NETPROFITMIN  S_PROFITNOTICE_NETPROFITMAX  \\\n",
       "0                          0.0                          0.0   \n",
       "1                      -9000.0                      -9000.0   \n",
       "2                      -9872.0                      -9872.0   \n",
       "\n",
       "                               S_PROFITNOTICE_REASON  \n",
       "0  1-9月,公司累计营业收入增长39.61%,但较2019年同期仍有明显下滑,目前处于亏损状态...  \n",
       "1  1、主营业务影响。受新冠肺炎疫情等因素影响,消费市场低迷,流通环节受限、下游需求收缩,公司葡...  \n",
       "2  公司财务部门将2021年度计提的固定资产减值准备4830万元,作非经常性损益处理,在审计时,...  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(\"\"\"\n",
    "select * from tbl_ep where code='600543.SH' and report_period=2021.12.31\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1425df79-bfaf-414a-9a12-f3d7e1231e5e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}