2013-02-20 70 views
0

我有这个查询,我想concat学生的名字。我应该在哪里放置concat语句?检索sql中的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表 -

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); 
) 

谢谢!

回答

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' 
+0

哇它的工作!谢谢你,先生Iswanto! – user2089597 2013-02-20 04:01:03

+0

不客气......你能接受答案吗? http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – 2013-02-20 04:02:13