如何通过以下方式编写用于生成结果的sql查询 [英] How to write sql query for generating result in the following way
本文介绍了如何通过以下方式编写用于生成结果的sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hai all
我有两个表,如下所示:-
hai all
i had two tables as follows:-
first table: Profile:
Id Name Age Designation_code
1 ABC 22 3
2 DEF 24 2
3 GHI 25 1
4 JKL 23 3
5 MNO 22 3
6 PQR 25 2
Second Table: Designation:
D_id Designation_name Designation_code
1 Consultant E1
2 Project Lead E2
3 Programmer E3
我想合并表格并希望以这种方式查询结果
i want to combine the tables and want the query result in this way
D_id Designation name Employees
1 Consultant GHI
2 Project Lead DEF
PQR
3 Programmer ABC
JKL
MNO
谁能帮我做到这一点...
知道要联接两个表的查询
can any one help me to do this...
know the query to join two table
SELECT p.Id,d.Designation_name,p.Name as Employee
FROM profile p
LEFT OUTER JOIN Designation d
ON p.Designation_code=d.Designation_code
但是结果如下所示
but the result is coming out as follows
D_id Designation name Employees
1 Consultant GHI
2 Project Lead DEF
3 Project Lead PQR
4 Programmer ABC
5 Programmer JKL
6 Programmer MNO
所以请任何人帮我
so please any one help me
推荐答案
如何编写用于生成结果的sql查询
知道要联接两个表的查询
但结果如下所示
在这种情况下,我不建议您通过查询来操作/过滤SQL查询的数据.
您从查询结果中得到的结果非常好.您不应尝试对查询进行任何进一步的更改以获得所需的结果.
在这里,最终结果是应该在UI端的前端中完成的事情.
取得整个结果,然后在UI中隐藏重复项.我之前已经与您分享了示例: ^ ]
再次重新发布毫无意义.如果您认为或不合适,请与您的上级/老师交谈以取得指导.
How to write sql query for generating result
know the query to join two table
but the result is coming out as follows
I would not suggest you that SQL queried data should be manipulated/filtered via query in this case.
What you got from query result is perfectly fine. You should not try to make any further changes in query to get the desired result.
Here, the final result is something that should be done in the front end on UI side.
Take the entire result and then hide the duplicate in the UI. I already shared exampled with you earlier: i want to populate grid view with data from more than two sql server tables[^]
No point in reposting again. If you think or don''t find it suitable, talk to your senior/teacher to get direction.
这篇关于如何通过以下方式编写用于生成结果的sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文