首页 \ 问答 \ 具有内部联接的ORACLE Listagg(ORACLE Listagg with an Inner Join)

具有内部联接的ORACLE Listagg(ORACLE Listagg with an Inner Join)

我需要从两个值匹配的两个表中提取数据。 连接表产生5行,并且总是产生5行。

有没有办法让我可以使用一个具有不同值的列并在一行中返回多个列?

例如:表A:orig_zip,dest_zip,pri_mode

表B:orig_zip,dest_zip,serv_comm

在执行内部连接时,表B将始终为表A中的每1个结果返回5个结果,如下所示:

SELECT a.orig_zip, a.dest_zip, b.serv_comm, a.pri_mode
FROM A a
INNER JOIN B b
ON a.orig_zip = b.orig_zip and a.dest_zip = b.dest_zip
ORDER BY a.orig_zip, a.dest_zip, b.mail_class;

如何获取5个结果,并将它们转换为oracle中的单个行。 结果中唯一不同的字段是serv_comm字段。

最后一行应该具有以下设置:

[ORIG_ZIP] [DEST_ZIP] [SERV_COMM1] [SERV_COMM2] [SERV_COMM3] [SERV_COMM4] [SERV_COMM5] [PRI_MODE]


I need to pull data from two tables where two values match. The joining table produces 5 rows, and will always produce 5 rows.

Is there a way that I can take one column with distinct values and return multiple columns in a single row?

For an example: Table A: orig_zip, dest_zip, pri_mode

Table B: orig_zip, dest_zip, serv_comm

Table B will always return 5 results for every 1 result in Table A when doing an inner join like the following:

SELECT a.orig_zip, a.dest_zip, b.serv_comm, a.pri_mode
FROM A a
INNER JOIN B b
ON a.orig_zip = b.orig_zip and a.dest_zip = b.dest_zip
ORDER BY a.orig_zip, a.dest_zip, b.mail_class;

How can I take the 5 results, and turn them into a single row in oracle. The only field that is different in the results will be the serv_comm field.

The final row should have the following setup:

[ORIG_ZIP][DEST_ZIP][SERV_COMM1][SERV_COMM2][SERV_COMM3][SERV_COMM4][SERV_COMM5][PRI_MODE]


原文:https://stackoverflow.com/questions/22355590
更新时间:2022-01-14 21:01

最满意答案

您可以使用getFirstVisiblePosition()来确定哪个项目是屏幕上的第一个项目。 接下来,您可以遍历子元素,直到找到与第一个可见位置对应的getTop() ,然后使用getTop()来计算其垂直偏移量。

int position = listView.getFirstVisiblePosition();
int offset = 0;
for (int i = 0; i < listView.getChildCount(); i++) {
    View child = listView.getChildAt(i);
    if (listView.getPositionForView(child) == position) {
        offset = child.getTop();
        break;
    }
}

您可以保存这些值并在返回时调用setSelectionFromTop(position offset)


You can use getFirstVisiblePosition() to figure out which item is the first on screen. Next you can iterate over the children until you find the one corresponding to the first visible position, and use getTop() to figure out its vertical offset.

int position = listView.getFirstVisiblePosition();
int offset = 0;
for (int i = 0; i < listView.getChildCount(); i++) {
    View child = listView.getChildAt(i);
    if (listView.getPositionForView(child) == position) {
        offset = child.getTop();
        break;
    }
}

You can save those values and use them on the way back to call setSelectionFromTop(position offset).

相关问答

更多
  • 您的ListView实际上可能非常小,但不会出现这种可见的溢出。 尝试在ListView的样式属性上设置flex: 1或height: 587 。 Your ListView might actually be quite small but not appear that way do to visible overflow. Try setting flex: 1 or height: 587 on your ListView's style property.
  • 好的,我找到一个解决方法,使用以下代码: View c = listview.getChildAt(0); int scrolly = -c.getTop() + listview.getFirstVisiblePosition() * c.getHeight(); 它的工作方式是第一个可见列表项的实际偏移量,并计算出距离视图的顶点多远,以确定我们“滚动到”视图的数量,所以现在我们知道我们可以计算其余的使用常规getFirstVisiblePosition方法。 Okay, I found a worka ...
  • 您可以使用getFirstVisiblePosition()来确定哪个项目是屏幕上的第一个项目。 接下来,您可以遍历子元素,直到找到与第一个可见位置对应的getTop() ,然后使用getTop()来计算其垂直偏移量。 int position = listView.getFirstVisiblePosition(); int offset = 0; for (int i = 0; i < listView.getChildCount(); i++) { View child = listView. ...
  • 尝试这个: // save index and top position int index = mList.getFirstVisiblePosition(); View v = mList.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop()); // ... // restore index and position mList.setSelectionFromTop(index, top); ...
  • 编辑 用这个: listView.post(new Runnable() { @Override public void run() { listView.smoothScrollToPositionFromTop(5, 0, 1); } }); Edit use this: listView.post(new Runnable() { @Override public void run() { lis ...
  • 听取onScrollStateChanged并在你的子类中保持状态是官方谷歌祝福的方式(参见API列表演示13 ,只有当列表完成滚动/投掷时才会在列表中加载数据)。 像大多数Android视图一样,我认为应用程序使用事件驱动的代码而不是轮询视图状态,并且允许访问内部滚动状态,这将鼓励开发人员进行错误的轮询类型行为。 Listening for onScrollStateChanged and keeping state in your subclass is the officially Google-bl ...
  • 最后我解决了这个问题,所以我决定为其他人发布解决方案: 在我的ListFragment子类中,我声明了两个int变量来保存滚动位置 public static class MyListFragment extends ListFragment { ...................... ...................... private int index = -1; private int top = 0; ...
  • 假设您知道所有项目的大小: int currentY = 0; for (int i = 0; i < listView.getFirstVisiblePosition(); i++) { int type = listView.getAdapter().getItemViewType(i); currentY += getHightForViewType(type); } int scrollY = -li ...
  • 可以使用savedInstanceState来保存ListView的精确滚动,但是在许多情况下这与活动一起销毁,并且我们不能轻易保存savedInstanceState,因为我们只能将其真正转换为Parcelable对象,而不是旨在坚持。 即使在尝试从ListView中获取savedInstanceState时,我们也会遇到一些问题。 通常会向我们返回null,因为Android文档指定在“没有什么有趣的保存”时发生。 那么,在这种情况下,滚动非常有趣! 可悲的是,Android并不总是会给我们这个,这带来 ...
  • 在iOS上,您可以使用ScrollView#contentOffset设置ListView的初始滚动位置,该位置继承ScrollView的属性。 如果您正在寻找Android解决方案,您调用的ListView.scrollTo方法似乎是一般情况下的最佳选择。 也就是说,如果我正确解释您的代码示例,您可能使用ListView作为分页的水平列表,也许借助于pagingEnabled属性? 如果是这种情况,在Android上您可能会考虑使用ViewPagerAndroid ,并设置initialPage属性。 O ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)