从多行中选择多列并返回包含总计数的行
好吧,这个解释起来有点复杂,我会尽力的,如果你不明白我欢迎你提问。
我有一个这样设计的表格:
TITLE |分公司 |分行1 |分支2 | BRANCH3
一个 BRANCH
(其中任何一个)可能包含“bank”、“credit”等等,
我想要做的是返回具有不同分支和计数的行,其中标题等于“xxx”
类似:
银行| xxx 结果
信用 | xxx 结果
等等。
ok, this is kind of complicated to explain, i will try my best, you are welcome to ask questions if you dont understand me.
i have a table desiged like this:
TITLE | BRANCH | BRANCH1 | BRANCH2 | BRANCH3
a BRANCH
(any of them) might contain "bank","credit" and so on
what i want to do, is return rows with distinct branches and count, where the title equals "xxx"
something like:
BANK | xxx Results
CREDIT | xxx Results
and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
如果您无法更改表格以符合1FN,则以下内容应该可以帮助您开始
使用
列,为您提供符合 1FN。UNION ALL
UNPIVOTTITLE
GROUP BY
和COUNT
结果SQL 语句
If you can't alter your tables to conform to 1FN, following should get you started
UNPIVOT
the columns using aUNION ALL
giving you a resultset that conforms to 1FN.TITLE
from this subselectGROUP BY
andCOUNT
the resultsSQL Statement