query.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package daily_base_column
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/models/response"
  5. )
  6. // GetDataByBaseColumnTickers17 获取数据指标
  7. func GetDataByBaseColumnTickers17(tickers []string) (list []*response.TickerDataItem, err error) {
  8. sql :=`SELECT
  9. ifnull(max(doo.date), max(dd.date)) AS date,
  10. dbc.base_column_ticker AS ticker,
  11. dbc.base_column_name,
  12. ifnull(
  13. (
  14. SELECT
  15. VALUE
  16. FROM
  17. daily_data
  18. WHERE
  19. ticker = dbc.base_column_ticker
  20. AND date = ifnull(max(doo.date), max(dd.date))
  21. ),
  22. (
  23. SELECT
  24. VALUE
  25. FROM
  26. daily_original
  27. WHERE
  28. ticker = dbc.base_column_ticker
  29. AND date = ifnull(max(doo.date), max(dd.date))
  30. )
  31. ) AS ticker_value,
  32. ifnull(
  33. (
  34. SELECT
  35. VALUE
  36. FROM
  37. daily_data
  38. WHERE
  39. ticker = dbc.base_column_ticker
  40. AND date < ifnull(max(doo.date), max(dd.date))
  41. ORDER BY
  42. date DESC
  43. LIMIT 1
  44. ),
  45. (
  46. SELECT
  47. VALUE
  48. FROM
  49. daily_original
  50. WHERE
  51. ticker = dbc.base_column_ticker
  52. AND date < ifnull(max(doo.date), max(dd.date))
  53. ORDER BY
  54. date DESC
  55. LIMIT 1
  56. )
  57. ) AS last_value
  58. FROM
  59. daily_base_column AS dbc
  60. LEFT JOIN daily_data AS dd ON dbc.base_column_ticker = dd.ticker
  61. LEFT JOIN daily_original AS doo ON dbc.base_column_ticker = doo.ticker
  62. WHERE
  63. dbc.base_column_ticker IN ?
  64. GROUP BY
  65. dbc.base_column_ticker`
  66. err = global.DEFAULT_MYSQL.Raw(sql, tickers).Scan(&list).Error
  67. return
  68. }
  69. // GetDataByBaseColumnTickers 获取数据指标
  70. func GetDataByBaseColumnTickers(tickers []string) (list []*response.TickerDataItem, err error) {
  71. sql :=`select ifnull(max(doo.date),max(dd.date)) as date,dbc.base_column_ticker as ticker,dbc.base_column_name ,
  72. ifnull((select value from daily_data where ticker = dbc.base_column_ticker and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1),(select value from daily_original where ticker = dbc.base_column_ticker and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1)) as ticker_value,
  73. ifnull((select value from daily_data where ticker = concat(dbc.base_column_ticker,'_dd') and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1),(select value from daily_original where ticker = concat(dbc.base_column_ticker,'_dd') and date <= ifnull(max(doo.date),max(dd.date))and value is not null order by date desc limit 1)) as dd_value,
  74. ifnull((select value from daily_data where ticker = concat(dbc.base_column_ticker,'_ww') and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1),(select value from daily_original where ticker = concat(dbc.base_column_ticker,'_ww') and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1)) as ww_value,
  75. ifnull((select value from daily_data where ticker = concat(dbc.base_column_ticker,'_mm') and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1),(select value from daily_original where ticker = concat(dbc.base_column_ticker,'_mm') and date <= ifnull(max(doo.date),max(dd.date)) and value is not null order by date desc limit 1)) as mm_value
  76. from
  77. daily_base_column AS dbc
  78. LEFT JOIN daily_data AS dd ON dbc.base_column_ticker = dd.ticker
  79. LEFT JOIN daily_original AS doo ON dbc.base_column_ticker = doo.ticker
  80. WHERE
  81. dbc.base_column_ticker IN ?
  82. GROUP BY
  83. dbc.base_column_ticker`
  84. err = global.DEFAULT_MYSQL.Raw(sql, tickers).Scan(&list).Error
  85. return
  86. }