编写动态SELECT语句

时间:2015-09-11 11:35:37

标签: mysql select

关于这个问题的一些建议:

select
    concat(MySourceTable,',',sid,'X',gid,'X',qid) as MySourceFieldname
from
    MySchemaTable
where
    SomeCriteria;

使用upper语句我得到一个字段名列表(仅一列)。 如何将其转换为水平显示(彼此相邻的字段)位置,以逗号分隔 我想生成一个'普通的“SELECT语句以供进一步使用。

@amixdon 输入是:

select concat('shape_survey_990113',sid,'X',gid,'X',qid) as lsfield -- <=MySourceFieldname
 from shape_questions -- <=MySchemaTable i.e. kind of dictionary
where question='result' -- <=SomeCriteria
  and sid=990113
  and language='en'
  order by lsfield;

输入结果如下(例如)

lsfields
---------
shape_survey_990113.990113X468X729,
shape_survey_990113.990113X469X733,
shape_survey_990113.990113X470X737,
....,

说明:sid,gid,qid是从与字典相当的表中获取的数字内容。这是我想要从中选择信息的源系统(不能更改)。它是一个开源调查工具。在此表中,处理每个调查的所有信息(数值990113正在识别许多中的一个特殊调查。上面的结尾是包含问题答案的最终字段名称。 'shape_survey_990113'是从以下位置选择firlds的表:

此选择结果应该看起来像是可以写入某个变量 (例如SET @MyFields = ...)

shape_survey_990113.990113X235X476, shape_survey_990113.990113X235X484, shape_survey_990113.990113X235X496

..将在下一步中用于组成一个真正的选择语句,如:

concat('SELECT ', @MyFields, ' FROM shape_survey_991103;')

不幸的是我无法上传这个屏幕截图,没有足够的声誉......

1 个答案:

答案 0 :(得分:0)

对于#include <opencv2\opencv.hpp> #include <iostream> #include<vector> using namespace cv; using namespace std; int main(){ VideoCapture capWebcam(0); if (capWebcam.isOpened() == false){ cout << "Error: camera not detected!!\n" << endl; return -1; } Mat matOriginal; // matrix object used to store image from webcam Mat matProcessed; vector<Vec3f> vecCircles; namedWindow("Original"); //window for original image namedWindow("Processed"); //window for Processed image char charCheckForEscKey = 0; while (charCheckForEscKey != 27){ //as long as ESC is not pressed, stays in the while if (!capWebcam.read(matOriginal)){ cout << "Error: image frame not read!!" << endl; break; } // inRange(matOriginal, //this time we don't need to pass a pointer; we pass the image as an object instead Scalar(0, 0, 175), //specify the lower bound of BGR we want to keep Scalar(100, 100, 256), //upper bound of BGR matProcessed); //return the processed image to another object GaussianBlur(matProcessed, matProcessed, Size(9, 9), 1.5, 1.5); //take matProcessed image and blur by Gaussian filter(9x9 window with std of 1.5 in both x,y direction) and return to same object HoughCircles(matProcessed, vecCircles, //use vector element to receive the x,y,radius of the detected circle CV_HOUGH_GRADIENT, //algorithms used to detect circles 2, //size of image divided by this value = "accumulator resolution" matProcessed.rows / 4, //min distance between the centers of two detected circles 100, //upper pixel value threshold for canny edge detection to interpret as edge 50, //lower pixel value threshold for canny edge detection to interpret as edge 10, //min radius of a circle can be detected 400); //max radius of a circle can be detected for (const auto& circ : vecCircles) //retrieve the x,y and radius of the detected circles from vecCircles object one by one { cout << "circle position x = " << circ[0] //because itrCircles is a pointer(pass by reference), to get the value need to use * to dereference << ",y = " << circ[1] << ",r = " << circ[2] << "\n" << endl; // draw the center of detected circle in green circle(matOriginal, Point(circ[0], circ[1]), 3, Scalar(0, 255, 0), CV_FILLED); // draw the circumference of detected circle circle(matOriginal, Point(circ[0], circ[1]), circ[2], Scalar(0, 0, 255), 3); } imshow("Original", matOriginal); //show the original mat(image) in Original window imshow("Processed", matProcessed);// show the processed mat(image) in Processed window charCheckForEscKey = waitKey(10); // delay 10 ms to allow a time gap to listen to any key pressed } // end while return(0); } // end main ,没有什么神圣的,而且有点亵渎。失去它。并丢失引用的逗号。像这样。

CONCAT()

尽可能简单。