在不使用全部工会的情况下获得全部工会的输出

时间:2019-12-13 13:06:42

标签: sql oracle oracle11g

在没有使用union的情况下,我可以找到2个表之间的公用记录。我能做到这一点。但是我无法做到“全联盟”。我的意思是我必须找出2个表的输出,包括不使用union all的重复表。反正有做吗?

table A has x column and values 1,2,3 
     and
table B has x column and values 3,4,5

select x from A union select x from B;
o/p 1,2,3,4,5

select x from A union all select x from B;
o/p should be 1,2,3,3,4,5,6(not necessarily in order)
我可以通过以下查询实现的

Union输出

select nvl(a.x,b.x) output from A full outer join B on A.x=b.X order by output;

但是如果不使用oracle内置union all,我将无法执行union all

3 个答案:

答案 0 :(得分:3)

您太接近答案了。

对于 @override Widget build(BuildContext context) { return Scaffold( body: CustomScrollView( slivers: <Widget>[ TransitionAppBar( extent: 250, avatar: Text("Rancho"), title: Container( margin: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0), decoration: BoxDecoration( color: Colors.grey[200], borderRadius: BorderRadius.all(Radius.circular(5.0))), child: Row(children: <Widget>[ Padding( padding: EdgeInsets.only(left: 20.0, right: 10.0), child: Icon(Icons.search), ), Expanded( child: TextFormField( keyboardType: TextInputType.text, textInputAction: TextInputAction.done, cursorColor: Colors.black, autofocus: false, style: TextField_Style, decoration: InputDecoration( filled: true, fillColor: Colors.transparent, contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 15), hintText: "Search", border: InputBorder.none, disabledBorder: OutlineInputBorder( borderSide: new BorderSide(color: Colors.transparent), borderRadius: new BorderRadius.circular(2), ), focusedBorder: OutlineInputBorder( borderSide: new BorderSide(color: Colors.transparent), borderRadius: new BorderRadius.circular(2), )), ), ) ]), ), ), SliverList( delegate: SliverChildBuilderDelegate((context, index) { return Container( color: Colors.blue, child: ListTile( title: Text("${index}a"), )); }, childCount: 25)) ], ), ); } ,您使用以下查询在x列上具有联接:

class TransitionAppBar extends StatelessWidget {
  final Widget avatar;
  final Widget title;
  final double extent;

  TransitionAppBar({this.avatar, this.title, this.extent = 250, Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SliverPersistentHeader(
      pinned: true,
      delegate: _TransitionAppBarDelegate(
        avatar: avatar,
        title: title,
        extent: extent > 200 ? extent : 200
      ),
    );
  }
}

class _TransitionAppBarDelegate extends SliverPersistentHeaderDelegate {
  final _avatarMarginTween = EdgeInsetsTween(
      begin: EdgeInsets.only(bottom: 70, left: 30),
      end: EdgeInsets.only(left: 0.0, top: 30.0));
  final _avatarAlignTween =
      AlignmentTween(begin: Alignment.bottomLeft, end: Alignment.topCenter);

  final Widget avatar;
  final Widget title;
  final double extent;

  _TransitionAppBarDelegate({this.avatar, this.title, this.extent = 250})
      : assert(avatar != null),
        assert(extent == null || extent >= 200),
        assert(title != null);

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    double tempVal = 34 * maxExtent / 100;
    final progress =  shrinkOffset > tempVal ? 1.0 : shrinkOffset / tempVal;
    print("Objechjkf === ${progress} ${shrinkOffset}");
    final avatarMargin = _avatarMarginTween.lerp(progress);
    final avatarAlign = _avatarAlignTween.lerp(progress);

    return Stack(
      children: <Widget>[
        AnimatedContainer(
          duration: Duration(milliseconds: 100),
          height: shrinkOffset * 2,
          constraints: BoxConstraints(maxHeight: minExtent),
          color: Colors.redAccent,
        ),
        Padding(
          padding: avatarMargin,
          child: Align(
            alignment: avatarAlign,
              child: avatar
          ),
        ),
        Padding(
          padding: EdgeInsets.only(bottom: 10),
          child: Align(
            alignment: Alignment.bottomCenter,
            child: title,
          ),
        )
      ],
    );
  }

  @override
  double get maxExtent => extent;

  @override
  double get minExtent => (maxExtent * 68) / 100;

  @override
  bool shouldRebuild(_TransitionAppBarDelegate oldDelegate) {
    return avatar != oldDelegate.avatar || title != oldDelegate.title;
  }
} 

对于union,您可以使用无法满足的连接条件。它将生成与select nvl(a.x,b.x) output from A full outer join B on A.x=b.X order by output; 相同的输出。

因此您必须使用以下查询:

union all

干杯!

答案 1 :(得分:1)

  

我必须找出2个表格的输出,包括重复而不使用   union all

select nvl(a.x, b.x) x from a full join b on a.x is null or b.x is null

dbfiddle

答案 2 :(得分:1)

如果提到某些边缘案例,您在面试中可能会获得加分,这可能是:

主键

如果其中一个表中的列不是主键(或主键唯一),则UNION

的建议解决方案
select nvl(a.x,b.x) output from A full outer join B on A.x=b.X

失败,您必须使用DISTINCT

select distinct  nvl(a.x,b.x) output from A full outer join B on A.x=b.X 

可空列

如果其中一个表中的列为可空UNION ALL提出的解决方案

select nvl(a.x, b.x) x from a full join b on a.x is null or b.x is null

失败。使用on 1=2的其他解决方案效果很好。