添加0值的行

时间:2017-04-10 18:30:43

标签: mysql select join insert

我的结果集如下:

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>

我需要展示另一个像:

fullDate            service          Monthlybilled
-----------------------------------------------------
2015-08-01          wash car         300.00
2015-10-01          brake test       500.00
2015-12-01          oil change       200.00

即。对于那些没有“检测到”活动的月份,我需要添加一行 说没有和0.00

有什么建议吗? 感谢

2 个答案:

答案 0 :(得分:1)

创建一个包含所需月份值的临时表。

然后将LEFT OUTER JOIN用于包含服务日期的表格。

SELECT
  alldates.fullDate,
  COALESCE(service.service, 'none') AS service,
  COALESCE(service.MonthlyBilled, 0.00) AS MonthlyBilled
FROM alldates
LEFT OUTER JOIN service
  ON alldates.fullDate = service.fullDate

答案 1 :(得分:1)

有三种方法可以做到这一点:

  1. 编写一个查询,生成范围之间的所有日期(如this SO answer中所述),并使用LEFT JOIN执行LEFT JOIN以获取所有日期为零条目。
  2. 创建一个日历表,用于维护所有日期,并使用当前查询2267 I rstest-compute: New RS 0x9f187000 2267 E RS Dispatch: Couldn't initialize dispatchTab.ScriptReduce 2267 V rsC++ : libRS.so init failed! 2267 I rstest-compute: Init returned 1 2267 I rstest-compute: Element 0x9f30e950 2267 I rstest-compute: Type 0x9f129c60 2267 I rstest-compute: Allocation 0x9f30e9f0 2267 I rstest-compute: Allocation 0x9f30ea40 0x9f30ea90 2284 E RenderScript: Unable to open shared library (/data/user/0/App1.Android//lib/librs.mono.so): (null) 2284 E RenderScript: Unable to open system shared library (/system/lib/librs.mono.so): (null) 2267 I rstest-compute: new script 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2267 E rsC++ : Internal error: Object id 0. 2284 E mono-rt : /proc/self/maps: 2267 E rsC++ : Internal error: Object id 0. 2284 E mono-rt : 2284 E mono-rt : No native Android stacktrace (see debuggerd output). 2284 E mono-rt : 2284 E mono-rt : 2284 E mono-rt : ================================================================= 2284 E mono-rt : Got a SIGSEGV while executing native code. This usually indicates 2284 E mono-rt : a fatal error in the mono runtime or one of the native libraries 2284 E mono-rt : used by your application. 2284 E mono-rt : ================================================================= 2284 E mono-rt : 2284 F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x2c in tid 2284 (App1.Android) 212 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 212 F DEBUG : Build fingerprint: 'samsung/j1minive3gjv/j1minive3g:6.0.1/MMB29Q/J106HJVU0AQB3:user/release-keys' 212 F DEBUG : Revision: '0' 212 F DEBUG : ABI: 'arm' 212 F DEBUG : pid: 2267, tid: 2284, name: App1.Android >>> App1.Android <<< 212 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2c 212 F DEBUG : r0 00000000 r1 00000000 r2 9f1afe00 r3 00000003 212 F DEBUG : r4 00000001 r5 9f12d000 r6 ffffffff r7 00000000 212 F DEBUG : r8 9ed71080 r9 9f12d21c sl 9f12d1f8 fp 00000008 212 F DEBUG : ip 9ee610dc sp 9ed71048 lr 9edd8d55 pc 9edd4eb0 cpsr 800f0030 212 F DEBUG : 212 F DEBUG : backtrace: 212 F DEBUG : #00 pc 00062eb0 /data/app/App1.Android-1/lib/arm/libRSSupport.so (_ZN7android12renderscript6Script9setVarObjEjPNS0_10ObjectBaseE+7) 212 F DEBUG : #01 pc 00066d53 /data/app/App1.Android-1/lib/arm/libRSSupport.so (_ZN7android12renderscript8ThreadIO16playCoreCommandsEPNS0_7ContextEi+238) 212 F DEBUG : #02 pc 0005ea87 /data/app/App1.Android-1/lib/arm/libRSSupport.so (_ZN7android12renderscript7Context10threadProcEPv+466) 212 F DEBUG : #03 pc 0003f83b /system/lib/libc.so (_ZL15__pthread_startPv+30) 212 F DEBUG : #04 pc 00019fdd /system/lib/libc.so (__start_thread+6) 2291 W ActivityManager: Force finishing activity App1.Android/md58adf3f2592a7497b73592b5e766304c2.MainActivity 212 F DEBUG : 212 F DEBUG : Tombstone written to: /data/tombstones/tombstone_03 212 E DEBUG : AM write failed: Broken pipe 1653 I BootReceiver: Copying /data/tombstones/tombstone_03 to DropBox (SYSTEM_TOMBSTONE) 212 E : ro.product_ship = true 212 E : ro.debug_level = 0x4f4c 2291 D InputDispatcher: Focused application set to: xxxx 212 E : sys.mobilecare.preload = false 2645 E audit : type=1701 msg=audit(1491844085.913:437): auid=4294967295 uid=10112 gid=10112 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=2284 comm="App1.Android" reason="memory violation" sig=11 2291 D ActivityTrigger: ActivityTrigger activityPauseTrigger 253 I Zygote : Process 2267 exited due to signal (11) 来获取所有记录。
  3. 在您的应用程序/服务层中编写逻辑,用0值填充缺少的日期。
  4. 我建议选项3。