问题描述
数据库不是我的强项,我不确定我所寻找的东西是否存在。总的来说,我很乐意为您提供任何可以正确指导我的建议。
我所拥有的:
我有多个查询,或者像下面这样想象:SELECT * FROM video WHERE video.name LIKE '%topspeed%' OR video.name LIKE '%%audi%';
让我们想象一下该查询的结果将是:
+------------+---------------+
| id | name |
+------------+---------------+
| 1 | My best audi |
| 2 | topspeed of mustang? |
| 3 | audi A7 topspeed |
| 4 | Do you like audi? |
| 5 | topspeed of audi Q8 |
+------------+---------------+
我需要什么:
有没有一种方法可以根据匹配的OR数对ORDER结果进行排序? 因此,换句话说,我希望原始示例的顺序为:+------------+---------------+
| id | name |
+------------+---------------+
| 5 | topspeed of audi Q8 |
| 3 | audi A7 topspeed |
| 1 | My best audi |
| 2 | topspeed of mustang? |
| 4 | Do you like audi? |
+------------+---------------+
解决方法
在MySQL中,您可以执行以下操作:
CustomPaint(
painter: CurveBackground(color: \\ yourColor),child: \\ your child
)
class CurveBackground extends CustomPainter {
final Color color;
CurveBackground({this.color});
@override
void paint(Canvas canvas,Size size) {
var paint = Paint();
paint.color = color;
paint.style = PaintingStyle.fill;
var path = Path();
path.moveTo(0,Dimens.size_30());
path.quadraticBezierTo(size.width * 0.4,size.height * 0.1,size.width * 0.3,size.height * 0.3);
path.quadraticBezierTo(size.width * 0.1,size.height * 0.6,size.width * 0.45,size.height * 0.7);
path.quadraticBezierTo(
size.width * 1,size.height * 0.9,size.width * 0.9,size.height * 1.0);
path.lineTo(size.width,size.height);
path.lineTo(0,size.height);
canvas.drawPath(path,paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
MySQL在数字上下文中将布尔值视为数字,其中SELECT v.*
FROM video v
WHERE v.name LIKE '%topspeed%' OR v.name LIKE '%audi%'
ORDER BY (v.name LIKE '%topspeed%') + (v.name LIKE '%audi%') DESC;
表示“ true”,1
表示“ false”。
请注意另外两个更改。我添加了一个表别名,以便在限定列名时更易于引用该表。我也将0
更改为'%%audi'
。连续两个'%audi%'
做不了'%'
做任何事。
考虑:
response.data.forEach(function(element){
Logger.log(element.phone.value)
});
合理性:在数字上下文中,MySQL条件表达式返回ORDER BY
(video.name LIKE '%topspeed%') + (video.name LIKE '%audi%') DESC,id
(如果为true),否则返回1
。因此,在两种情况下都匹配的视频的值为0
,而在一种情况下匹配的视频的指标仅为2
。您可以对此使用降序排序。我在1
子句中添加了另一个条件,以通过打破联系获得确定性排序。
SELECT
id,name,(CASE WHEN video.name LIKE '%topspeed%' THEN 1 ELSE 0 END +
CASE WHEN video.name LIKE '%%audi%' THEN 1 ELSE 0 END) as score
FROM video WHERE video.name LIKE '%topspeed%' OR video.name LIKE '%%audi%'
ORDER BY score DESC;
此查询在MS-SQL上也有效,这就是为什么我使用CASE WHEN....END
。