zoukankan      html  css  js  c++  java
  • 多表求和

    1.有一个用户表users,两个文章表articles_1,articles_2。
    如果得出articles_1中的tickets字段以及articles_2中的tickets字段的和。条件是与users中userid相同的记录。

    select  userid,
    articlesCount = isnull((select sum(A1.tickets) from articles_1 A1 where A1.userid = U.userid),0) +
    isnull((select sum(A2.tickets) from articles_2 A2 where A2.userid = U.userid),0)
    from users U

    可以查出users表中所有user的articles的数量,列articlesCount的值就是这个和!

    2.select
      (
    select count(*) from a)as info_1,
      (
    select sum(Hits) from a) as info_2,
      (
    select count(*) from b) as info_3,
      (
    select count(*) from c) as info_4

  • 相关阅读:
    LabVIEW入门第三天(软件及驱动包下载)
    poj1732
    poj1722
    poj1821
    poj1770
    poj1949
    poj1726
    poj1699
    poj1682
    poj1853
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/1374139.html
Copyright © 2011-2022 走看看