我在下面选择查询:
SELECT t2.email AS email, t2.extname AS extname, t2.lastname AS lastname, t2.id_status AS id_status, t2.is_active AS is_active, t2.firstname AS firstname, t2.ldapuser AS ldapuser, t2.middlename AS middlename, t2.studid AS studid, t2.picture AS picture, t3.butuanaddress AS butuanaddress, t3.age AS age, t3.credential AS credential, t3.dateadmission AS dateadmission, t3.citizenship AS citizenship, t3.dategrad AS dategrad, t3.dateofbirth AS dateofbirth, t3.degree1 AS degree1, t3.elementary AS elementary, t3.fathername AS fathername, t3.fatherocc AS fatherocc, t3.gpa AS gpa, t3.guardian_phone AS guardian_phone, t3.homeaddress AS homeaddress, t3.guardian AS guardian, t3.homephone AS homephone, t3.homezipcode AS homezipcode, t3.honor AS honor, t3.mobile AS mobile, t3.maritalstatus AS maritalstatus, t3.hs AS hs, t3.lastskul AS lastskul, t3.mothername AS mothername, t3.placeofbirth AS placeofbirth, t3.religion AS religion, t3.remark3 AS remark3, t3.motherocc AS motherocc, t3.remarks AS remarks, t3.resno AS resno, t3.scholarship AS scholarship, t3.sai AS sai, t3.sex AS sex, t3.sonumber AS sonumber, t3.spouse AS spouse, t3.studid AS t3_studid, t3.yr_elementary AS yr_elementary, t3.yr_hs AS yr_hs, t3.yr_last AS yr_last, t4.block AS block, t4.cur_year AS cur_year, t4.dategrad AS t4_dategrad, t4.encoder AS encoder, t4.gpa AS t4_gpa, t4.maxload AS maxload, t4.scholarcode AS scholarcode, t4.regdate AS regdate, t4.standing AS standing, t4.sem AS sem, t4.status AS status, t4.studid AS t4_studid, t4.studlevel2 AS studlevel2, t4.studlevel AS studlevel, t4.studmajor AS studmajor, t4.studload AS studload, t4.studmajor1 AS studmajor1, t4.studmajor2 AS studmajor2, t4.sy AS sy, t1.college AS college, t1.is_active AS t1_is_active, t1.major AS major, t1.masteral AS masteral, t1.phd AS phd, t1.progcode AS progcode, t1.progdept AS progdept, t1.progdesc AS progdesc, t1.undergrad AS undergrad
FROM
student t2
INNER JOIN studinfo t3 ON t2.studid=t3.studid
INNER JOIN semstudent t4 ON t3.studid=t4.studid
INNER JOIN program t1 ON t1.progcode=t4.studmajor
WHERE (t2.studid::text ILIKE '101-03043')
ORDER BY t2.studid ASC
它产生了9行同样的结果。我该怎么办才能产生独特的结果。我想要做的是使用相同的数据对行进行GROUP。这可能吗?
P.S:
DISTINCT does not do anything in my query results.
以下是7个查询结果中的2个。
"jr";"jr";"ononononononononon";1;;"ericka";"";"enganio";"101-03043";"Bayho";"";20;"SPR, Picture, Form 138,Form 137,GM, NSO Birth, Medical Cert";"2010-04-23";"";"2014-04-03";"1994-04-06";"";"general t. de leon elementary school";"Sabeniano L. Villongco";"Driving";92.67;"aaaaaaaaaaaaaaa";"P-4 Eureka, Brgy. Maug, Butuan City";"";"";8600;"";"aaaaaaaaaaaaaaa";"SINGLE";"Banza National High School";"";"Dinah E. Villongco";"Golden Ribbon, Butuan City";"Judaism";"";"";"FOR EMPLOYMENT PURPOSES ONLY";"18-09, SERIES 2014";"";104;"FEMALE";"";"";"101-03043";"2006";"2010";"";"";"2008";"";"ajpondog";1.9300;28.00;"12";"2011-11-11";"REGULAR";"2nd";"OLD";"101-03043";"";2;"BSCS";27.00;"";"";"2011-2012";"CEIT";t;"";f;f;"BSCS";"DCSIT";"BACHELOR OF SCIENCE IN COMPUTER SCIENCE";t
"jr";"jr";"ononononononononon";1;;"krissy";"";"enganio";"101-03043";"Bayho";"";20;"SPR, Picture, Form 138,Form 137,GM, NSO Birth, Medical Cert";"2010-04-23";"";"2014-04-03";"1994-04-06";"";"general t. de leon elementary school";"Sabeniano L. Villongco";"Driving";92.67;"aaaaaaaaaaaaaaa";"P-4 Eureka, Brgy. Maug, Butuan City";"";"";8600;"";"aaaaaaaaaaaaaaa";"SINGLE";"Banza National High School";"";"Dinah E. Reid";"Golden Ribbon, Butuan City";"Judaism";"";"";"FOR EMPLOYMENT PURPOSES ONLY";"18-09, SERIES 2014";"";104;"FEMALE";"";"";"101-03043";"2006";"2010";"";"";"2008";"";"jqtimosan";2.0800;6.00;"0";"2013-04-11";"REGULAR";"Sum";"OLD";"101-03043";"";3;"BSCS";6.00;"";"";"2012-2013";"CEIT";t;"";f;f;"BSCS";"DCSIT";"BACHELOR OF SCIENCE IN COMPUTER SCIENCE";t
答案 0 :(得分:1)
使用distinct:
SELECT Distinct t2.email AS email, t2.extname AS extname, t2.lastname AS lastname, t2.id_status AS id_status, t2.is_active AS is_active, t2.firstname AS firstname, t2.ldapuser AS ldapuser, t2.middlename AS middlename, t2.studid AS studid, t2.picture AS picture, t3.butuanaddress AS butuanaddress, t3.age AS age, t3.credential AS credential, t3.dateadmission AS dateadmission, t3.citizenship AS citizenship, t3.dategrad AS dategrad, t3.dateofbirth AS dateofbirth, t3.degree1 AS degree1, t3.elementary AS elementary, t3.fathername AS fathername, t3.fatherocc AS fatherocc, t3.gpa AS gpa, t3.guardian_phone AS guardian_phone, t3.homeaddress AS homeaddress, t3.guardian AS guardian, t3.homephone AS homephone, t3.homezipcode AS homezipcode, t3.honor AS honor, t3.mobile AS mobile, t3.maritalstatus AS maritalstatus, t3.hs AS hs, t3.lastskul AS lastskul, t3.mothername AS mothername, t3.placeofbirth AS placeofbirth, t3.religion AS religion, t3.remark3 AS remark3, t3.motherocc AS motherocc, t3.remarks AS remarks, t3.resno AS resno, t3.scholarship AS scholarship, t3.sai AS sai, t3.sex AS sex, t3.sonumber AS sonumber, t3.spouse AS spouse, t3.studid AS t3_studid, t3.yr_elementary AS yr_elementary, t3.yr_hs AS yr_hs, t3.yr_last AS yr_last, t4.block AS block, t4.cur_year AS cur_year, t4.dategrad AS t4_dategrad, t4.encoder AS encoder, t4.gpa AS t4_gpa, t4.maxload AS maxload, t4.scholarcode AS scholarcode, t4.regdate AS regdate, t4.standing AS standing, t4.sem AS sem, t4.status AS status, t4.studid AS t4_studid, t4.studlevel2 AS studlevel2, t4.studlevel AS studlevel, t4.studmajor AS studmajor, t4.studload AS studload, t4.studmajor1 AS studmajor1, t4.studmajor2 AS studmajor2, t4.sy AS sy, t1.college AS college, t1.is_active AS t1_is_active, t1.major AS major, t1.masteral AS masteral, t1.phd AS phd, t1.progcode AS progcode, t1.progdept AS progdept, t1.progdesc AS progdesc, t1.undergrad AS undergrad
FROM
student t2
INNER JOIN studinfo t3 ON t2.studid=t3.studid
INNER JOIN semstudent t4 ON t3.studid=t4.studid
INNER JOIN program t1 ON t1.progcode=t4.studmajor
WHERE (t2.studid::text ILIKE '101-03043')
ORDER BY t2.studid ASC
如果您只希望对字段的子集进行区分,请在group by子句中添加仅需要区分的字段。
删除distinct并在查询末尾添加如下内容:
group by x1,y1,.........
答案 1 :(得分:0)
我认为你需要的是DISTINCT:
SELECT DISTINCT t2.email AS email, t2.extname AS extname, t2.lastname AS lastname, t2.id_status AS id_status, t2.is_active AS is_active, t2.firstname AS firstname, t2.ldapuser AS ldapuser, t2.middlename AS middlename, t2.studid AS studid, t2.picture AS picture, t3.butuanaddress AS butuanaddress, t3.age AS age, t3.credential AS credential, t3.dateadmission AS dateadmission, t3.citizenship AS citizenship, t3.dategrad AS dategrad, t3.dateofbirth AS dateofbirth, t3.degree1 AS degree1, t3.elementary AS elementary, t3.fathername AS fathername, t3.fatherocc AS fatherocc, t3.gpa AS gpa, t3.guardian_phone AS guardian_phone, t3.homeaddress AS homeaddress, t3.guardian AS guardian, t3.homephone AS homephone, t3.homezipcode AS homezipcode, t3.honor AS honor, t3.mobile AS mobile, t3.maritalstatus AS maritalstatus, t3.hs AS hs, t3.lastskul AS lastskul, t3.mothername AS mothername, t3.placeofbirth AS placeofbirth, t3.religion AS religion, t3.remark3 AS remark3, t3.motherocc AS motherocc, t3.remarks AS remarks, t3.resno AS resno, t3.scholarship AS scholarship, t3.sai AS sai, t3.sex AS sex, t3.sonumber AS sonumber, t3.spouse AS spouse, t3.studid AS t3_studid, t3.yr_elementary AS yr_elementary, t3.yr_hs AS yr_hs, t3.yr_last AS yr_last, t4.block AS block, t4.cur_year AS cur_year, t4.dategrad AS t4_dategrad, t4.encoder AS encoder, t4.gpa AS t4_gpa, t4.maxload AS maxload, t4.scholarcode AS scholarcode, t4.regdate AS regdate, t4.standing AS standing, t4.sem AS sem, t4.status AS status, t4.studid AS t4_studid, t4.studlevel2 AS studlevel2, t4.studlevel AS studlevel, t4.studmajor AS studmajor, t4.studload AS studload, t4.studmajor1 AS studmajor1, t4.studmajor2 AS studmajor2, t4.sy AS sy, t1.college AS college, t1.is_active AS t1_is_active, t1.major AS major, t1.masteral AS masteral, t1.phd AS phd, t1.progcode AS progcode, t1.progdept AS progdept, t1.progdesc AS progdesc, t1.undergrad AS undergrad
FROM
student t2
INNER JOIN studinfo t3 ON t2.studid=t3.studid
INNER JOIN semstudent t4 ON t3.studid=t4.studid
INNER JOIN program t1 ON t1.progcode=t4.studmajor
WHERE (t2.studid::text ILIKE '101-03043')
ORDER BY t2.studid ASC
Distinct使得具有所有相同结果的行仅在结果中出现一次。