从数据库

时间:2016-05-21 10:40:04

标签: mysql sql

如何通过他的位置(行)获取表名?我有很多桌子。

例如,在从表中查找的列中,它以这种方式工作:

SELECT COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'database name here' 
AND TABLE_NAME = 'table name here' 
AND ORDINAL_POSITION = 2;

我需要这样的东西才能在数据库中按位置(行)查找表名。

使用MySQL。 感谢。

2 个答案:

答案 0 :(得分:0)

如果我理解正确,你需要类似的东西

SELECT position, TABLE_NAME
FROM (

  SELECT @row := @row +1 AS position, TABLE_NAME
  FROM INFORMATION_SCHEMA.TABLES
  JOIN (
   SELECT @row :=0
  )r
  WHERE TABLE_SCHEMA =  'TABLE_SCHEMA here'
)tmp
WHERE position =5

和另一种方法

SET @row =0;
SELECT TABLE_NAME
FROM (
   SELECT @row := @row +1 AS position, TABLE_NAME
   FROM INFORMATION_SCHEMA.TABLES
   WHERE TABLE_SCHEMA =  'TABLE_SCHEMA here'
)tmp
WHERE position =5

答案 1 :(得分:0)

看起来你想要这样的东西:

import numpy as np
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
np.random.seed(2016)

def make_colormap(seq):
    """Return a LinearSegmentedColormap
    seq: a sequence of floats and RGB-tuples. 
      - Every float is sandwiched between two RGB values.
      - The floats indicate locations (on a scale from 0.0 to 1.0) where the
        color map transitions from one RGB color to the next.
      - The floats should be in increasing order
      - The first and last values in the sequence are the first and last
        colors in color map.
    https://stackoverflow.com/q/16834861/190597 (unutbu)
    """
    seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
    cdict = {'red': [], 'green': [], 'blue': []}
    for i, item in enumerate(seq):
        if isinstance(item, float):
            r1, g1, b1 = seq[i - 1]
            r2, g2, b2 = seq[i + 1]
            cdict['red'].append([item, r1, r2])
            cdict['green'].append([item, g1, g2])
            cdict['blue'].append([item, b1, b2])
    return mcolors.LinearSegmentedColormap('CustomMap', cdict)

c = mcolors.ColorConverter().to_rgb
cmap = make_colormap([(0,1,0), c('dark green')])
cmap.set_under('burnt red')
cmap.set_over('yellow green')

arr = np.random.randint(0, 102, size=(11, 11))
# modify arr so that 0 is mapped to a negative number (-2) and 1 is mapped to a
# positive number greater than 100, (say, 102), and all other values are
# decreased by 2
arr -= 2   
arr = np.where(arr==-1, 102, arr)

plt.imshow(arr, interpolation='nearest', cmap=cmap, vmin=0, vmax=100)
plt.colorbar(extend='both')
plt.show()

这将返回作为该DB的第二个表创建的表中的所有列。