必须在查询中进行哪些更改。帮助我。提前 [英] what changes have to be made in query. help me with this. thanx in advance

查看:50
本文介绍了必须在查询中进行哪些更改。帮助我。提前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是查询



here is query

SELECT   c.Customer_CNIC,g.Guarantor_CNIC FROM Customer c,Guaronters g where g.Customer_CNIC=c.Customer_CNIC and c.Customer_CNIC=''12345-1234567-8'' order by c.Customer_CNIC









im得到的结果为:





i m getting result as:

Customer_CNIC         Guarantor_CNIC
12345-1234567-8       78663-2349875-6
12345-1234567-8       87676-5765757-6



但我希望如下:


but i want as:

Customer_CNIC         Guarantor_CNIC
12345-1234567-8       78663-2349875-6
                      87676-5765757-6

推荐答案

SQL中没有我知道的机制可以做这是有充分理由的。

SQL不是关于数据的表示,每一行都是自包含的,而不是依赖于早期的结果(因为记录的处理顺序不是由SQL Server保证。



要做到这一点,你就是吧ld必须创建一个Stored过程,该过程将行选入临时表并循环遍历它们,从而创建第二个临时表以进行输出。令人讨厌,效率低下。



这是一个在表示层中更容易处理的任务,无论编码是什么。
There is no mechanism I know of in SQL to do that, and for good reason.
SQL is not about presentation of the data, each row is intended to be self contained, and not to rely on earlier results (because the order of processing of records is not guaranteed by SQL Server).

To do that, you would have to create a Stored procedure that selected the rows into a temporary table and looped through them creating a second temporary table for output. Nasty, and inefficient.

This is a task with is much, much more easily handled in the presentation layer, whatever that happens to be coded in.


正如我之前写的:SQL不是''可视化''数据!

As i wrote before: SQL is not for ''visualize'' data!
PIEBALDconsult写道:
PIEBALDconsult wrote:



这不是一个演示系统;这是一种查询和操作数据的语言。


That is not a system for presentation; that is a language for querying and manipulating data.




OriginalGriff写道:
OriginalGriff wrote:

SQL不是关于演示文稿数据,每一行都是自包含的(...)

SQL is not about presentation of the data, each row is intended to be self contained (...)



我们需要多少次重复它?



BTW:

你需要阅读 JOIN [ ^ ]声明。使用加入 [ ^ ],你可以从两个检索数​​据或更多表基于表之间的逻辑关系。例如:


How many times we need to repeat it?

BTW:
You need to read about JOIN[^] statement. By using joins[^], you can retrieve data from two or more tables based on logical relationships between the tables. For example:

SELECT   c.Customer_CNIC, g.Guarantor_CNIC
FROM Customer c INNER JOIN Guaronters g ON g.Customer_CNIC=c.Customer_CNIC 
WHERE c.Customer_CNIC='12345-1234567-8'
ORDER BY c.Customer_CNIC





提示(实现OriginalGriff所写的):

1)如何创建表 [ ^ ]? - 部分临时表。你会在那里找到有关如何将数据插入临时表的信息。

2)如何查看记录集合?使用光标 [ ^ ]和WHILE [ ^ ]命令 - section: B.在游标中使用WHILE



Tips (to achieve that what OriginalGriff wrote):
1) How to CREATE TABLE[^]? - section Temporary tables. There you''ll find informations about: how to insert data into temporary table.
2) How to go through the collection of records? Use cursor[^] and WHILE[^] command - section: B. Using WHILE in a cursor.


正如其他人所说,格式化不应该使用SQL来完成。但是如果你仍然出于某种原因想要这样做,根据数据库,你可以使用LAG。



例如,看看:如何从上一行或下一行中获取数据结果集 [ ^ ]
As said by others, formatting shouldn''t be done using SQL. But if you still for some reason want to do it, depending on the database, you could use LAG.

For example, have a look at: How to fetch data from the previous or next rows in the resultset[^]


这篇关于必须在查询中进行哪些更改。帮助我。提前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆