具有内部联接的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
最满意答案
您可以使用
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 usegetTop()
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 fails to scroll)[2023-10-16]
您的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. ...
-
维护/保存/恢复滚动位置返回到ListView(Maintain/Save/Restore scroll position when returning to a ListView)[2022-07-27]
尝试这个: // 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; ...
-
android获取listview的滚动位置,填充不同的高度(android get scroll position of listview populated with varied height)[2022-12-28]
假设您知道所有项目的大小: 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并不总是会给我们这个,这带来 ...
-
设置React Native ListView的初始滚动位置(Setting an initial scroll position of a React Native ListView)[2021-10-12]
在iOS上,您可以使用ScrollView#contentOffset设置ListView的初始滚动位置,该位置继承ScrollView的属性。 如果您正在寻找Android解决方案,您调用的ListView.scrollTo方法似乎是一般情况下的最佳选择。 也就是说,如果我正确解释您的代码示例,您可能使用ListView作为分页的水平列表,也许借助于pagingEnabled属性? 如果是这种情况,在Android上您可能会考虑使用ViewPagerAndroid ,并设置initialPage属性。 O ...