首页
\
问答
\
如何重复显示重复值一次,如果重复,则显示“ - ”(How can I display repeated values only one time and have '-' if it repeats)
如何重复显示重复值一次,如果重复,则显示“ - ”(How can I display repeated values only one time and have '-' if it repeats)
我有一些子查询可以为每个PolicyNumber检索相同的值。 如何用' - '替换重复值,并且只在每个策略的顶行显示一个? 现在我有这个: 但是我需要这样的东西:
SELECT -------------/* GrossPremium*/ (SELECT ISNULL(SUM(tblFin_InvoiceDetails.AmtBilled), 0) FROM tblFin_InvoiceDetails WITH (NOLOCK) WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)) AS GrossPremium --------------/*CompanyCommissionPercentage*/ ,((SELECT ISNULL(SUM(tblFin_InvoiceDetails.MGAAmt), 0) FROM tblFin_InvoiceDetails WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)) + CASE WHEN INV.Remitter = 'B' then (SELECT ISNULL(SUM(tblFin_InvoiceDetails.RemitterAmt), 0) FROM tblFin_InvoiceDetails WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum))----------------RemitterCommission ELSE (SELECT ISNULL(SUM(tblFin_InvoicedItemsPayees.PayeeAmt), 0) FROM tblFin_InvoicedItemsPayees INNER JOIN tblFin_PolicyCharges pc on pc.ChargeCode = tblFin_InvoicedItemsPayees.ChargeCode and pc.chargeType = 'P' WHERE (tblFin_InvoicedItemsPayees.InvoiceNum = INV.InvoiceNum and tblFin_InvoicedItemsPayees.PayeeGuid = INV.ProducerLocationGuid)) END) * 100 / NULLIF((SELECT ISNULL(SUM(tblFin_InvoiceDetails.AmtBilled), 0) FROM tblFin_InvoiceDetails WITH (NOLOCK) WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)),0) AS CompanyCommissionPercentage FROM [tblFin_PayablesWorking] PW INNER JOIN tblFin_Invoices INV ON PW.InvoiceNumber=INV.InvoiceNum
I have some subqueries that retreives the same values for each PolicyNumber. How can I substitute repeated value with '-' and only display it one in a top row for each policy? Right now I have this: But I need something like this:
SELECT -------------/* GrossPremium*/ (SELECT ISNULL(SUM(tblFin_InvoiceDetails.AmtBilled), 0) FROM tblFin_InvoiceDetails WITH (NOLOCK) WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)) AS GrossPremium --------------/*CompanyCommissionPercentage*/ ,((SELECT ISNULL(SUM(tblFin_InvoiceDetails.MGAAmt), 0) FROM tblFin_InvoiceDetails WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)) + CASE WHEN INV.Remitter = 'B' then (SELECT ISNULL(SUM(tblFin_InvoiceDetails.RemitterAmt), 0) FROM tblFin_InvoiceDetails WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum))----------------RemitterCommission ELSE (SELECT ISNULL(SUM(tblFin_InvoicedItemsPayees.PayeeAmt), 0) FROM tblFin_InvoicedItemsPayees INNER JOIN tblFin_PolicyCharges pc on pc.ChargeCode = tblFin_InvoicedItemsPayees.ChargeCode and pc.chargeType = 'P' WHERE (tblFin_InvoicedItemsPayees.InvoiceNum = INV.InvoiceNum and tblFin_InvoicedItemsPayees.PayeeGuid = INV.ProducerLocationGuid)) END) * 100 / NULLIF((SELECT ISNULL(SUM(tblFin_InvoiceDetails.AmtBilled), 0) FROM tblFin_InvoiceDetails WITH (NOLOCK) WHERE (tblFin_InvoiceDetails.ChargeType = 'P') AND (tblFin_InvoiceDetails.InvoiceNum = INV.InvoiceNum)),0) AS CompanyCommissionPercentage FROM [tblFin_PayablesWorking] PW INNER JOIN tblFin_Invoices INV ON PW.InvoiceNumber=INV.InvoiceNum
原文:https://stackoverflow.com/questions/39605127
更新时间:2024-04-23 11:04
最满意答案
如果我理解正确,首先要确定与给定
datetime
范围内的多个category
关联的username
值:SELECT username FROM myTable WHERE datetime BETWEEN :start AND :end GROUP BY username HAVING COUNT(DISTINCT category) > 1
然后,您想要检索给定
datetime
范围内的所有记录,这些用户名按username
和datetime
时间排序:SELECT * FROM myTable NATURAL JOIN ( SELECT username FROM myTable WHERE datetime BETWEEN :start AND :end GROUP BY username HAVING COUNT(DISTINCT category) > 1 ) t WHERE datetime BETWEEN :start AND :end ORDER BY username, datetime
If I've understood correctly, you first want identify those
username
values that are associated with more than onecategory
in the givendatetime
range:SELECT username FROM myTable WHERE datetime BETWEEN :start AND :end GROUP BY username HAVING COUNT(DISTINCT category) > 1
And then you want to retrieve all records within the given
datetime
range for those usernames, sorted byusername
anddatetime
:SELECT * FROM myTable NATURAL JOIN ( SELECT username FROM myTable WHERE datetime BETWEEN :start AND :end GROUP BY username HAVING COUNT(DISTINCT category) > 1 ) t WHERE datetime BETWEEN :start AND :end ORDER BY username, datetime
相关问答
更多-
count计算给定参数的非null值的数量。 您拥有的dis_id每个注释创建一行,其中dis_id和com_id都不为null ,因此它们的计数将相同。 由于这些是ID,您可以只计算distinct的出现次数以获得您想要的响应: (编辑:根据评论中的请求添加了一个order by子句) SELECT p.PRO_Name, COUNT(DISTINCT d.DIS_Id) AS nofdisc, COUNT(DISTINCT c.COM_Id) AS nof ...
-
您可以在日期列上使用聚合函数MIN: SELECT MIN(r.RN_EXECUTION_DATE), t.TESTSETNAME, r.RN_BUILD_VERSION, r.rn_status, COUNT(r.rn_run_id) AS run_count FROM table t, table r, (.........) tlf WHERE (........) GROUP BY t.TESTSETNAME, r.RN_BUILD_VERSION, r.rn_status OR ...
-
查询在一个字段中相同但在另一个字段中不同的记录?(Query for records that are the same in one field, but different in another?)[2021-12-20]
有了SQLite,我相信你最好的选择是自我加入: SELECT DISTINCT t1.*, t2.* FROM yourtable as t1 INNER JOIN yourtable as t2 ON t1.model_number = t2.model_number AND t1.primary_use <> t2.primary_use; 将表连接到自己,其中model_number是相同的,但primary_use是不同的,然后返回不同的结果应该给你你想要 ... -
function print_dropdown($query, $link,$field0,$field1){ $queried = mysql_query($query, $link); $menu = '
相关文章
更多- The Log: What every software engineer should know about real-time data's unifying abstraction
- Apache Solr 实现去掉重复的搜索结果
- Real-Time Rendering 笔记 --- 1-4章
- 利用SOLR搭建企业搜索平台 之八(solr 实现去掉重复的搜索结果,打SOLR-236_collapsing.patch补丁)
- 关于 style="display:none" 得问题
- display控件格式化时间日期的问题?
- 通过xml配置搞定Struts重复提交问题(转)
- 关于mysql数据库memory表数据重复问题
- Who AM I Casting Crowns自我简介
- Groovy 文件I/O 操作详解
最新问答
更多- CSS修复容器和溢出元素(CSS Fix container and overflow elements)
- SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
- nginx 80端口反向代理多个域名,怎样隐藏端口的
- xcode提醒样式,swift 3(xcode alert style, swift 3)
- 在Chrome控制台中调试JavaScript(debugging javascript in Chrome console)
- Javascript - 试图围绕自定义事件(Javascript - Trying to wrap my head around custom events)
- 边栏链接不可点击(Sidebar links aren't clickable)
- 使用recpatcha gem时如何显示其他表单错误?(How do I display other form errors when using the recpatcha gem?)
- boost.python避免两次注册内部类,但仍然在python中公开(boost.python Avoid registering inner class twice but still expose in python)
- Android 现在软件很少吗?以后会多起来吗
- 如何在ActiveAdmin 0.5.0中为资源全局指定预先加载?(How to specify eager loading globally for a resource in ActiveAdmin 0.5.0?)
- matlab代码为黄金比例持续分数(matlab code for golden ratio continued fraction)
- Android浏览器触摸事件位置(Android browser touch event location)
- 将cURL输出分配给Bash中的变量(Assign output to variable in Bash)
- 我如何在MVC视图上没有时间获取当前日期(how i can get current date without time on MVC view)
- sql连接函数(sql join of function)
- 为什么在Xamarin Media插件中使用ImageSource.FromStream而不是FromFile?(Why use ImageSource.FromStream instead of FromFile in Xamarin Media plugin?)
- 这段代码是否真的可以防止SQL注入?(Will this code actually work against SQL-injection? [duplicate])
- 信阳方远计算机学校大专证被国家认可么
- React / Rails AJAX POST请求返回404(React/Rails AJAX POST request returns 404)
- Android与php服务器交互(Android interact with php server)
- 自动刷新QTableWidget可能吗?(Refresh QTableWidget automatically possible?)
- JVM / Compiler优化对象的未使用属性(optimization of unused properties of object by JVM / Compiler)
- 插入表格时,乌克兰字符会更改为问号(Ukrainian character change to question mark when insert to table)
- 在头文件中包含异常类(Including an exception class in a header file)
- 完成c#中的执行后关闭sqlcmd(Close sqlcmd after finishing executing in c#)
- 使用软导航栏正确检测屏幕尺寸(Detecting screensize correctly with soft navigation bar)
- Typescript:从输入更新值(Typescript : update value from input)
- 如何在执行某些行后仅在断点处停止?(How to only stop at a breakpoint after some line was executed?)
- 以未定义的元素在JSON中循环(loop in JSON with undefined elements)