如何隐藏SQL选择查询中的特定文本请帮帮我 [英] How to hide particular text from SQL select query please help me

查看:126
本文介绍了如何隐藏SQL选择查询中的特定文本请帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个查询,有三个表,我使用内连接和分组方法

组依赖三种类型的GST

1)0.00

2)2.5

3)9.00



i只想显示2.5和9.00如何隐藏0.00 pdgst

并显示5.00代替2.5和18.00代替9.00



请帮助我.....



我尝试了什么:



I write a query there are three table and i used inner join and Group By method
Group are depend three type of GST
1) 0.00
2) 2.5
3) 9.00

i want to show only 2.5, and 9.00 how to hide the 0.00 pdgst
and show 5.00 in place of 2.5 and 18.00 in place of 9.00

Please Help me.....

What I have tried:

select p.prtgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst,sum(prd.totaltaxamt)As Rate,sum(prd.TaxableAmt)As Taxable_Amount
from TBL_pur_inv as pr
 INNER JOIN tbl_party_ldg  AS p   ON pr.partyIDpur = p.partyID
 INNER JOIN TBL_pur_invdet  AS prd   ON pr.purinvid = prd.purinvid
 
where purinvdt ='2018-01-04'  GROUP BY p.prtgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst

推荐答案

您的请求没有任何押韵或理由,或者至少我们无法作为基于该小数据的通用解决方案。为什么0被忽略?这很容易做到:

There isn't any rhyme or reason to your request, or at least none we can do as a generic solution based on that little data. Why is 0 to be ignored? That's easy to do:
SELECT ... WHERE ValueIDontWant != 0.0



但其余的?为什么一个值加倍,另一个值减半?它适用多少个值?他们都是?最大和最小?第一和最后?我们不知道 - 我们无法从您的查询中解决这个问题,因为我们不知道您的表或其数据是什么样的。

而且查询本身看起来就像您猜到的那样,因为我不相信你真的想按这些专栏分组。你确实意识到你添加到GROUP BY的每一列增加了返回的行数,而不是减少它,不是吗?



停下来,坐下来,看看在你的数据表中以及你想要返回的内容,并在开始编写查询之前考虑一切是如何相关的!


But the rest? Why would one value be doubled, and the other halved? How many values does it apply to? All of them? Max and min? First and last? We don't know - and we can't work it out from your query because we have no idea what your tables or their data looks like.
And the query itself looks like you guessed, as I do not believe you really want to group by each of those columns. You do realise that each column you add to a GROUP BY increases the number of rows return, not reduces it, don't you?

Stop, sit down, look at your data tables and exactly what you are trying to return, and think about how everything relates before you start writing queries!


除了OriginalGriff的答案之外......



看看HAVING&与GROUP BY一起使用时的WHERE子句 - 参考; 有和有/哪里的条款有区别的地方 [ ^ ]

主要区别在于应用子句时 - 在分组之前应用于数据的位置,在分组之后应用了 - 这允许您使用聚合函数。



亲切的问候
In addition to OriginalGriff's answer..

Take a look at the HAVING & WHERE clauses when used with GROUP BY - refer; Where Vs Having / Difference between having and Where clause [^]
The main difference is when the clauses are applied - Where is applied to the data prior to grouping, Having is applied after grouping - this allows you to use aggregate functions.

Kind Regards


这篇关于如何隐藏SQL选择查询中的特定文本请帮帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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