I m trying to create a data abstraction in SQL where I can choose the quarter I want to look at for my employee info. Right now I m using the naming system Q1_P1_N for "Quarter 1 Project 1 name" and Q1_P1_W is "...project 1 weight." Employees can work on multiple projects. So far what I have is:
CREATE PROCEDURE effort_lookup4(IN proj_name VARCHAR(20), IN quarter INT(1))
BEGIN
SET @Qx_P1_N = CONCAT( Q , quarter, _P1_N );
SET @Qx_P2_N = CONCAT( Q , quarter, _P2_N );
SET @Qx_P1_W = CONCAT( Q , quarter, _P1_W );
SET @Qx_P2_W = CONCAT( Q , quarter, _P2_W );
SET @var1 = (SELECT sum(@Qx_P1_W) FROM table_test WHERE @Qx_P1_N = proj_name);
SET @var2 = (SELECT sum(@Qx_P2_W) FROM table_test WHERE @Qx_P2_N = proj_name);
我的问题是,每当我调用“%x_P1_N”或“%x_P1_W”的查询时,我实际上不会通过正确的查询,我无法找出我做错了什么。这应该很容易。我只是新来使用 SQL 。
这里请举一个表格外观的例子, 除了它会穿插到 Q2_P1_N,
+------+---------+---------+---------+---------+
| EMPID| Q1_P1_N | Q1_P2_N | Q1_P1_W | Q1_P2_W |
+------+---------+---------+---------+---------+
| 1000 | ProjA | ProjB | 0.50 | 0.50 |
| 1001 | ProjA | NULL | 1.00 | NULL |
| 1010 | ProjB | NULL | 1.00 | NULL |
| 1011 | ProjA | ProjB | 0.50 | 0.50 |
+------+---------+---------+---------+---------+
谢谢 谢谢