我有这个查询,我想要连接学生的名字。我应该把concat声明放在哪里?
“的concat(文本,LPAD(ID,如图4所示, '0'))”
此处的文字和ID来自学生表。这是查询:
"SELECT p.*, s.* FROM students s, payments p
where s.id=p.id and level='Grade 3' and amount>='1500'"
表
-students table -
create table students(
text char(5)NOT NULL,
id int(11)NOT NULL AUTO_INCREMENT,
name varchar(250),
address varchar(250)
PRIMARY KEY(id)
)
-payments -
create table payments(
p_id int(11)NOT NULL AUTO_INCREMENT,
amount varchar(250),
id int,
PRIMARY KEY(p_id)
FOREIGN KEY(id) REFERENCES students(id);
)
谢谢!
答案 0 :(得分:1)
试试这个:
SELECT p.*, s.*, concat(s.text,LPAD(s.id,4,'0')) as student_names
FROM students s, payments p
where s.id=p.id and level='Grade 3' and amount>='1500'