我必须获得所有过程完成的记录。
表格:
Id Process_ind run_id
1 Y 100
2 Y 100
3 Y 100
4 Y 200
5 Y 200
6 N 200
在这种情况下,我只希望run_id作为输出bcz,所有进程ind均为“ Y”。 ID是主键
答案 0 :(得分:1)
您可以使用import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _selectedRegion;
String _selectedSecond;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Something before'),
DropdownButton<String>(
value: _selectedRegion,
items: ['Arizona', 'California']
.map((region) => DropdownMenuItem<String>(
child: Text(region), value: region))
.toList(),
onChanged: (newValue) {
setState(() {
_selectedRegion = newValue;
});
},
),
_addSecondDropdown(),
Text('Something after'),
],
),
),
);
}
Widget _addSecondDropdown() {
return _selectedRegion != null
? DropdownButton<String>(
value: _selectedSecond,
items: ['First', 'Second']
.map((region) => DropdownMenuItem<String>(
child: Text(region), value: region))
.toList(),
onChanged: (newValue) {
setState(() {
_selectedSecond = newValue;
});
})
: Container(); // Return an empty Container instead.
}
}
:
not exists
如果只想要select t.*
from table t
where not exists (select 1 from table t1 where t1.run_id = t.run_id and t1.Process_ind = 'N');
,那么也可以选择run_id
:
GROUP BY
答案 1 :(得分:0)
也许是这样的:
select distinct run_id from your_table where process_ind = 'Y'
答案 2 :(得分:0)
GROUP BY和HAVING可以做到。
在COUNT中使用CASE WHEN可以得出特定的总数。
SELECT run_id
FROM Table
GROUP BY run_id
HAVING COUNT(*) = COUNT(CASE WHEN Process_ind = 'Y' THEN 1 END)
ORDER BY run_id
答案 3 :(得分:0)
您可以使用not in
select distinct run_id from your_table
where run_id not in( select run_id from your_table where process_ind = 'N' )