262. Trips and Users - 行程和用户 <Hard>

该SQL查询从Trips表中获取2013年10月1日至2013年10月3日期间,非禁止用户的取消率。通过连接Users表确保司机和乘客未被禁止,并计算取消订单('cancelled_by_client'或'cancelled_by_driver')与总订单数量的比例。结果按日期展示,保留两位小数。

Trips 表中存所有出租车的行程信息。每段行程有唯一键 Id,Client_Id 和 Driver_Id 是 Users 表中 Users_Id 的外键。Status 是枚举类型,枚举成员为 (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’)。

+----+-----------+-----------+---------+--------------------+----------+
| Id | Client_Id | Driver_Id | City_Id |        Status      |Request_at|
+----+-----------+-----------+---------+--------------------+----------+
| 1  |     1     |    10     |    1    |     completed      |2013-10-01|
| 2  |     2     |    11     |    1    | cancelled_by_driver|2013-10-01|
| 3  |     3     |    12     |    6    |     completed      |2013-10-01|
| 4  |     4     |    13     |    6    | cancelled_by_client|2013-10-01|
| 5  |     1     |    10     |    1    |     completed      |2013-10-02|
| 6  |     2     |    11     |    6    |     completed      |2013-10-02|
| 7  |     3     |    12     |    6    |     completed      |2013-10-02|
| 8  |     2     |    12     |    12   |     completed      |2013-10-03|
| 9  |     3     |    10     |    12   |     completed      |2013-10-03| 
| 10 |     4     |    13     |    12   | cancelled_by_driver|2013-10-03|
+----+-----------+-----------+---------+--------------------+----------+
Users 表存所有用户。每个用户有唯一键 Users_Id。Banned 表示这个用户是否被禁止,Role 则是一个表示(‘client’, ‘driver’, ‘partner’)的枚举类型。

+----------+--------+--------+
| Users_Id | Banned |  Role  |
+----------+--------+--------+
|    1     |   No   | client |
|    2     |   Yes  | client |
|    3     |   No   | client |
|    4     |   No   | client |
|    10    |   No   | driver |
|    11    |   No   | driver |
|    12    |   No   | driver |
|    13    |   No   | driver |
+----------+--------+--------+
写一段 SQL 语句查出 2013年10月1日 至 2013年10月3日 期间非禁止用户的取消率。基于上表,你的 SQL 语句应返回如下结果,取消率(Cancellation Rate)保留两位小数。

取消率的计算方式如下:(被司机或乘客取消的非禁止用户生成的订单数量) / (非禁止用户生成的订单总数)

+------------+-------------------+
|     Day    | Cancellation Rate |
+------------+-------------------+
| 2013-10-01 |       0.33        |
| 2013-10-02 |       0.00        |
| 2013-10-03 |       0.50        |
+------------+-------------------+

 

分析:主表 - Trips 表,

被司机或乘客取消的非禁止用户生成的订单数量'cancelled_by_client' or 'cancelled_by_driver'like 'cancelled_%'

非禁止用户生成的订单总数:需要保证trip表司机与乘客非ban!需要两个User表实例关联对应字段~

 

ps:注意sum与count函数的区别 !

sum(),求和累加,不计算空值;

count(),求行数,空值认为没有此项;

 

# count(IF(a.Status = 'cancelled_by_client' or a.Status = 'cancelled_by_driver' ,1, NULL))
# count(IF(a.Status like 'cancelled_%' ,1, NULL))
# sum(IF(a.Status like 'cancelled_%' ,1, 0)
# count(case when a.Status like 'cancelled_%' then 1 else NULL end)
# sum(a.Status != 'completed')

select Request_at as Day,round(sum(IF(a.Status like 'cancelled_%' ,1, 0))/count(*),2) as `Cancellation Rate`
from Trips a
left join Users b on b.Users_Id = a.Client_Id
left join Users c on c.Users_Id = a.Driver_Id
where b.Banned = 'No' and c.Banned = 'No'
and a.Request_at between '2013-10-01' and '2013-10-03'
group by a.Request_at

 

我现在要实现VBUS唤醒系统,(即系统休眠后插入usb可以实现唤醒系统,并且有adb口,目前是休眠之后插入usb无法唤醒) 目前抓到的唤醒log如下: [ 282.641013] PM: pm_system_irq_wakeup: 175 triggered c263000.thermal-sensor [ 282.641764] PM: PM: Pending Wakeup Sources: [timerfd] [ 282.669925] usb_extcon_detect_cable : id = 1, vbus = 0 [ 282.709202] [drm] [msm-dsi-warn]: secondary default panel not found 我的预期是id = 1, vbus = 1 这是log打印相关的代码: static void usb_extcon_detect_cable(struct work_struct *work) { int id, vbus; struct usb_extcon_info *info = container_of(to_delayed_work(work), struct usb_extcon_info, wq_detcable); /* check ID and VBUS and update cable state */ id = info->id_gpiod ? gpiod_get_value_cansleep(info->id_gpiod) : 1; vbus = info->vbus_gpiod ? gpiod_get_value_cansleep(info->vbus_gpiod) : id; printk("ct %s : id = %d, vbus = %d\n", __func__, id, vbus); /* at first we clean states which are no longer active */ if (id) { if (info->vbus_out_gpiod) gpiod_set_value_cansleep(info->vbus_out_gpiod, 0); extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); } if (!vbus) extcon_set_state_sync(info->edev, EXTCON_USB, false); if (!id) { if (info->vbus_out_gpiod) gpiod_set_value_cansleep(info->vbus_out_gpiod, 1); extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); } else { if (vbus) extcon_set_state_sync(info->edev, EXTCON_USB, true); } } 这是我在devicetree/qcom/neo-pmic-overlay.dtsi的配置:你检查下哪些地方可能配置的不对: #include <dt-bindings/gpio/gpio.h> #include <dt-bindings/pinctrl/qcom,pmic-gpio.h> #include <dt-bindings/iio/qcom,spmi-vadc.h> #include <dt-bindings/interrupt-controller/irq.h> #include "pm8150.dtsi" &pm8150_gpios { usb0_vbus_det { usb0_vbus_det_default: usb0_vbus_det_default { pins = "gpio5"; function = "normal"; input-enable; bias-disable; //power-source = <0>; /* 1.8V input supply */ }; }; }; &soc { reboot_reason { compatible = "qcom,reboot-reason"; nvmem-cells = <&restart_reason>; nvmem-cell-names = "restart_reason"; }; gpio_keys { compatible = "gpio-keys"; label = "gpio-keys"; pinctrl-names = "default"; pinctrl-0 = <&gpio_vol_up>, <&gpio_camera_shot>; vol_up { label = "vol_up"; gpios = <&tlmm 122 GPIO_ACTIVE_LOW>; linux,input-type = <1>; linux,code = <KEY_VOLUMEUP>; debounce-interval = <15>; linux,can-disable; }; camera_shot { label = "camera_shot"; gpios = <&tlmm 64 GPIO_ACTIVE_LOW>; linux,input-type = <1>; linux,code = <KEY_CAMERA>; debounce-interval = <15>; linux,can-disable; }; }; extcon_usb0: extcon_usb0 { compatible = "linux,extcon-usb-gpio"; vbus-gpio = <&pm8150_gpios 5 GPIO_ACTIVE_HIGH>; interrupt-parent = <&spmi_bus>; interrupts = <0x0 0xc9 0 IRQ_TYPE_EDGE_BOTH>; interrupt-names = "pm8150_gpio5"; wakeup-source; pinctrl-names = "default"; pinctrl-0 = <&usb0_vbus_det_default>; }; }; &pm8150_vadc { pm8150_skin_therm { reg = <ADC5_AMUX_THM1_100K_PU>; label = "pm8150_skin_temp"; qcom,hw-settle-time = <200>; qcom,ratiometric; qcom,pre-scaling = <1 1>; }; /* * This thermistor has 100k pullup already connected, * modify config following HW recommendation, for all * platforms other than SG. */ pm8150_wlan_therm { reg = <ADC5_AMUX_THM2>; label = "pm8150_wlan_temp"; qcom,hw-settle-time = <200>; qcom,pre-scaling = <1 1>; qcom,scale-fn-type = <ADC_SCALE_HW_CALIB_THERM_100K_PULLUP>; }; pm8150_xo_therm { reg = <ADC5_XO_THERM_100K_PU>; label = "pm8150_xo_therm"; qcom,hw-settle-time = <600>; qcom,ratiometric; qcom,pre-scaling = <1 1>; }; }; &pm8150_adc_tm { io-channels = <&pm8150_vadc ADC5_AMUX_THM1_100K_PU>, <&pm8150_vadc ADC5_AMUX_THM2>, <&pm8150_vadc ADC5_XO_THERM_100K_PU>; pm8150_skin_therm { reg = <ADC5_AMUX_THM1_100K_PU>; qcom,hw-settle-time = <200>; qcom,ratiometric; }; /* * This thermistor has 100k pullup already connected, * modify config following HW recommendation, for all * platforms other than SG. */ pm8150_wlan_therm { reg = <ADC5_AMUX_THM2>; qcom,hw-settle-time = <200>; }; pm8150_xo_therm { reg = <ADC5_XO_THERM_100K_PU>; qcom,hw-settle-time = <600>; qcom,ratiometric; }; }; &thermal_zones { sys-therm-0 { polling-delay-passive = <0>; polling-delay = <0>; thermal-sensors = <&pm8150_adc_tm ADC5_AMUX_THM1_100K_PU>; trips { active-config0 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; active-config1 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; }; }; sys-therm-1 { polling-delay-passive = <0>; polling-delay = <0>; thermal-sensors = <&pm8150_adc_tm ADC5_AMUX_THM2>; trips { active-config0 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; active-config1 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; sys_therm1_config0: sys-therm1-config0 { temperature = <54000>; hysteresis = <2000>; type = "passive"; }; sys_therm1_config1: sys-therm1-config1 { temperature = <56000>; hysteresis = <2000>; type = "passive"; }; sys_therm1_config2: sys-therm1-config2 { temperature = <58000>; hysteresis = <2000>; type = "passive"; }; }; }; xo-therm { polling-delay-passive = <0>; polling-delay = <0>; thermal-sensors = <&pm8150_adc_tm ADC5_XO_THERM_100K_PU>; trips { active-config0 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; active-config1 { temperature = <125000>; hysteresis = <1000>; type = "passive"; }; }; }; }; &qupv3_se10_i2c { clock-frequency = <400000>; #address-cells = <1>; #size-cells = <0>; status = "ok"; battery: battery { compatible = "simple-battery"; voltage-min-design-microvolt = <3100000>; energy-full-design-microwatt-hours = <2520000>; charge-full-design-microamp-hours = <645000>; over-voltage-threshold-microvolt = <4500000>; re-charge-voltage-microvolt = <250000>; /* bq256xx's termination current setting has a min limit of 60mA */ charge-term-current-microamp = <60000>; constant-charge-current-max-microamp = <500000>; constant-charge-voltage-max-microvolt = <4480000>; voltage-max-design-microvolt = <4480000>; precharge-current-microamp = <128000>; factory-internal-resistance-micro-ohms = <120000>; }; charger: charger@6b { compatible = "ti,bq25600"; reg = <0x6b>; interrupt-parent = <&tlmm>; interrupts = <6 IRQ_TYPE_EDGE_FALLING>; debugboard-detect-gpio = <&tlmm 54 GPIO_ACTIVE_HIGH>; ti,watchdog-timeout-ms = <0>; pinctrl-names = "default"; pinctrl-0 = <&bq256xx_intr_default>; input-voltage-limit-microvolt = <4480000>; input-current-limit-microamp = <500000>; monitored-battery = <&battery>; status = "ok"; }; battery_645mAh: battery_645mAh { qmax-cell0 = <16384>; resist-table = <34 31 29 33 39 26 31 28 28 29 31 31 46 83 221>; }; battery_630mAh: battery_630mAh { qmax-cell0 = <15656>; resist-table = <16 16 17 20 22 13 17 18 18 18 17 23 28 44 62>; }; bq27421: fuel-gauge@55 { compatible = "ti,bq27421"; reg = <0x55>; interrupt-parent = <&tlmm>; interrupts = <7 IRQ_TYPE_EDGE_FALLING>; pinctrl-names = "default"; pinctrl-0 = <&bq27421_intr_default>; bat-resist-table = <&battery_645mAh>; monitored-battery = <&battery>; status = "ok"; }; }; &usb0 { extcon = <&extcon_usb0>, <&eud>; }; &pm8150_pon { qcom,log-kpd-event; }; 补充一下,gpio5注册的中断号是cat /proc/interrupts | grep spmi 304: 0 0 0 0 spmi-gpio 4 Edge soc:extcon_usb0 我 cat /proc/interrupts | grep spmi 304: 0 0 0 0 spmi-gpio 4 Edge soc:extcon_usb0 而代码里interrupt-parent = <&spmi_bus>;这两者需要对应吗
最新发布
08-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值