想要一个搜索查询,在群组搜索方面提供精确的输出?

时间:2018-02-09 07:05:19

标签: sql sql-server

大家好,我被困在搜索中,下面给出了3张表,即发票表,服务表和税务明细表,以便您更好地理解

我需要在下面的表格中搜索sql查询如果我将参数作为税务明细表的taxId传递,并希望输出如下所示。

请大家帮我解决这个问题,并建议我单一的SQL查询,如果我从任何人那里得到确切的查询,我会支持他的帐户。

1)发票表

<table border=1>
<tr><td>Invoiceid(PK)</td><td>Client</td><td>Amount</td><td>Tax</td><td>totalamount</td>
</tr>
<tr>
  <td>1</td><td>abc</td><td>12500</td>
  <td>1000</td><td>13500</td>
</tr>
<tr>
  <td>2</td><td>xyz</td><td>6280</td>
  <td>1000</td><td>7280</td>
</tr>
<tr>
  <td>3</td><td>mno</td><td>10000</td>
  <td>1000</td><td>11000</td>
</tr>
<tr>
  <td>4</td><td>efg</td><td>5600</td>
  <td>400</td><td>6000</td>
</tr>
<tr>
  <td>5</td><td>pqr</td><td>5000</td>
  <td>1000</td><td>6000</td>
</tr>
<tr>
  <td>6</td><td>rst</td><td>3000</td>
  <td>0</td><td>3000</td>
</tr>
<tr>
  <td>7</td><td>jkl</td><td>3800</td>
  <td>1200</td><td>5000</td>
</tr>

</table>

2)服务表

<table border=1>
<tr><td>Invoiceserviceid(PK)</td><td>Invoiceid(FK)</td>
  <td>Serviceid</td><td>Amount</td>
</tr>
<tr>
  <td>1</td><td>1</td>
  <td>12</td><td>8000</td>
</tr>
<tr>
  <td>2</td><td>1</td>
  <td>16</td><td>4500</td>
</tr>
<tr>
  <td>3</td><td>2</td>
  <td>17</td><td>1000</td>
</tr>
<tr>
  <td>4</td><td>2</td>
  <td>22</td><td>1100</td>
</tr>
<tr>
  <td>5</td><td>2</td>
  <td>36</td><td>2200</td>
</tr>
<tr>
  <td>6</td><td>2</td>
  <td>46</td><td>1980</td>
</tr>
<tr>
  <td>7</td><td>3</td>
  <td>75</td><td>10000</td>
</tr>
<tr>
  <td>8</td><td>4</td>
  <td>69</td><td>2500</td>
</tr>
<tr>
  <td>9</td><td>4</td>
  <td>88</td><td>3600</td>
</tr>
<tr>
  <td>10</td><td>5</td>
  <td>89</td><td>5000</td>
</tr>
<tr>
  <td>11</td><td>6</td>
  <td>90</td><td>2000</td>
</tr>
<tr>
  <td>12</td><td>6</td>
  <td>15</td><td>1000</td>
</tr>
<tr>
  <td>13</td><td>7</td>
  <td>32</td><td>3800</td>
</tr>
</table>

3)税务明细表

<table border=1>
<tr><td>taxdetailid(PK)</td><td>Invoiceid(FK)</td>
  <td>taxid</td><td>Taxname</td>
  <td>taxamount</td>
</tr>
<tr>
  <td>1</td><td>1</td><td>1</td>
  <td>GST</td><td>1000</td>
</tr>
<tr>
  <td>2</td><td>2</td><td>2</td>
  <td>CGST</td><td>500</td>
</tr>
<tr>
  <td>3</td><td>2</td><td>3</td>
  <td>SGST</td><td>500</td>
</tr>
<tr>
  <td>4</td><td>3</td><td>1</td>
  <td>GST</td><td>500</td>
</tr>
<tr>
  <td>5</td><td>3</td><td>2</td>
  <td>CGST</td><td>250</td>
</tr>
<tr>
  <td>6</td><td>3</td><td>3</td>
  <td>SGST</td><td>250</td>
</tr>
<tr>
  <td>7</td><td>4</td><td>1</td>
  <td>GST</td><td>300</td>
</tr>
<tr>
  <td>8</td><td>4</td><td>3</td>
  <td>SGST</td><td>100</td>
</tr>
<tr>
  <td>9</td><td>5</td><td>2</td>
  <td>CGST</td><td>1000</td>
</tr>
<tr>
  <td>10</td><td>7</td><td>1</td>
  <td>GST</td><td>1200</td>
</tr>

</table>

OUT PUT

传递税务明细表

的参数'Taxid'

Pass Parameter value (1)
<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>1</td><td>abc</td><td>12</td><td>8000</td>
</tr>
<tr><td>1</td><td>abc</td><td>16</td><td>4500</td>
</tr>
<tr><td>7</td><td>jkl</td><td>32</td><td>3800</td>
</tr>
</table>

Pass Parameter value (2,3)

<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>2</td><td>xyz</td><td>17</td><td>1000</td>
</tr>
<tr><td>2</td><td>xyz</td><td>22</td><td>1100</td>
</tr>
<tr><td>2</td><td>xyz</td><td>36</td><td>2200</td>
</tr>
<tr><td>2</td><td>xyz</td><td>46</td><td>1980</td>
</tr>
</table>


Pass Parameter value (NULL)

<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>6</td><td>rst</td><td>90</td><td>2000</td>
</tr>
<tr><td>6</td><td>rst</td><td>15</td><td>1000</td>
</tr>
</table>

也传递

  1. 参数(1,2,3)结果invoiceid(3)
  2. 参数(2)结果invoiceid(5)
  3. 参数(1,3)结果invoiceid(4)

0 个答案:

没有答案