问:
ASP.Net How can I access the correct item in the list
I am still a beginner in the ASP.Net world.
My question is I think pretty easy to answer.

I have a list of products that are displayed with a foreach in the view:

```<code>@using (Html.BeginForm("Edit", "Products")){
<table class="table">
    <thead class="thead-dark">
        <tr>
            <th scope="col">Id</th>
            <th scope="col">Info</th>
            <th scope="col">Count</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var product in Model.ProductsList)
        {
            <tr>
                <th scope="row">@Html.HiddenFor(x => product.Id)</th>
                <td>@Html.TextBoxFor(x => product.Info) </td>
                <td>@Html.TextBoxFor(x => product.Count) </td>
            </tr>
        }
    </tbody>
</table>
<button type="submit" class="btn btn-primary">Save</button>}
</code>```

If I now try to get to the right element with this method, for example: There are 10 elements in the list and I click on the 5 element and change the info.
If I now click on Save I should get back the 5 element I have edited in my method.

```<code>  [HttpPost]
    public ActionResult Edit(Product product)
    {
        if (product == null)
            return HttpNotFound();

        using (var _context = new Models.Database_.WebContext())
        {
            var result = _context.Products.SingleOrDefault(x => x.Id == product.Id);
        }
        return RedirectToAction("Index");
    }
</code>```

I think what I am missing is that I have to give the ID ?!
The error is that my ID is always 0.

答:
You dont necessarily have to pass an Id since you are passing the whole model from your view. Your model is not being binded to your ActionResult parameter Product. Therefore, you get null object.

Change your code to this:

```<code><th scope="row">@Html.Hidden("Id", product.Id)</th>
<td>@Html.TextBox("Info", product.Info) </td>
<td>@Html.TextBox("Count", product.Count) </td>
</code>```

As I remember,the "name" attribute is used for mapping. So after above changes, if you inspect (F12 on browser) your HTML you will see "name" attribute will be appended to your HTML elements.

Also I notice a problem that your ActionResult accepts Product object but in your view you are submitting the list of products. Not sure why you doing so.

Body:
I am still a beginner in the ASP.Net world.
My question is I think pretty easy to answer.

I have a list of products that are displayed with a foreach in the view:

@using (Html.BeginForm("Edit", "Products")){

            Id
            Info
            Count

        @foreach (var product in Model.ProductsList)
        {

                @Html.HiddenFor(x => product.Id)
                @Html.TextBoxFor(x => product.Info)
                @Html.TextBoxFor(x => product.Count)

        }

<button type="submit" class="btn btn-primary">Save</button>}

If I now try to get to the right element with this method, for example: There are 10 elements in the list and I click on the 5 element and change the info.
If I now click on Save I should get back the 5 element I have edited in my method.

  [HttpPost]
    public ActionResult Edit(Product product)
    {
        if (product == null)
            return HttpNotFound();

        using (var _context = new Models.Database_.WebContext())
        {
            var result = _context.Products.SingleOrDefault(x => x.Id == product.Id);
        }
        return RedirectToAction("Index");
    }

I think what I am missing is that I have to give the ID ?!
The error is that my ID is always 0.

Body:
You dont necessarily have to pass an Id since you are passing the whole model from your view. Your model is not being binded to your ActionResult parameter Product. Therefore, you get null object.

Change your code to this:

<th scope="row">@Html.Hidden("Id", product.Id)</th>
<td>@Html.TextBox("Info", product.Info) </td>
<td>@Html.TextBox("Count", product.Count) </td>

As I remember,the "name" attribute is used for mapping. So after above changes, if you inspect (F12 on browser) your HTML you will see "name" attribute will be appended to your HTML elements.

Also I notice a problem that your ActionResult accepts Product object but in your view you are submitting the list of products. Not sure why you doing so.


来源: stackexchange

问:
Django initial form values from db query in views
I'm trying to set initial values in form for editing within views. For example i want to edit book that is allready stored in database setting initial values from database query. Is it possible in django ?
For instance:

views.py:

```<code>from .models import Book
from .forms import BookForm

def edit_book(request,book_id):
    query_book=Book.objects.get(pk=book_id)
    Book_form_to_edit =BookForm(initial=query_book)
    context={
    'book_form':Book_form_to_edit,
    }
    return render(request,'edit_book.html',context)
</code>```

Thank you in advance.

答:
Yess, it is possible try referring the code below. I have edited your code so you will grab some idea on it.

```<code>from .models import Book
from .forms import BookForm

def edit_book(request,book_id):
    query_book=Book.objects.get(pk=book_id)
    Book_form_to_edit =BookForm(request.POST, instance=query_book)

    if Book_form_to_edit.is_valid():
      Book_form_to_edit.save()

    context={
      'book_form':Book_form_to_edit,
    }
    return render(request,'edit_book.html',context)
</code>```

and in url.py make sure to get the book_id

```<code>path('<int:book_id>/Edit/', views.edit_view, name='edit')
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to set initial values in form for editing within views. For example i want to edit book that is allready stored in database setting initial values from database query. Is it possible in django ?
For instance:

views.py:

from .models import Book
from .forms import BookForm

def edit_book(request,book_id):
    query_book=Book.objects.get(pk=book_id)
    Book_form_to_edit =BookForm(initial=query_book)
    context={
    'book_form':Book_form_to_edit,
    }
    return render(request,'edit_book.html',context)

Thank you in advance.

Body:
Yess, it is possible try referring the code below. I have edited your code so you will grab some idea on it.

from .models import Book
from .forms import BookForm

def edit_book(request,book_id):
    query_book=Book.objects.get(pk=book_id)
    Book_form_to_edit =BookForm(request.POST, instance=query_book)

    if Book_form_to_edit.is_valid():
      Book_form_to_edit.save()

    context={
      'book_form':Book_form_to_edit,
    }
    return render(request,'edit_book.html',context)

and in url.py make sure to get the book_id

path('<int:book_id>/Edit/', views.edit_view, name='edit')


问:
I want to obtain following list in text instead of objects using twitter api in ruby programming language
I'd love to obtain following list in text (screen names) instead of objects using Twitter Api.  I am new to Ruby programming language and this's my first attempt using api with ruby especially Twitter api. What I expect is list of screen names instead of objects and I will show you examples bellow:

Results I get currently:
current results

Desired and expected results

I've tried methods such as .full_text and .text appended to the objects and didn't get my desired results.I've searched almost everywhere especially here in Stackoverflow and didn't find my answer yet.

This's my code below:

```<code>require 'rubygems'
require 'bundler/setup'

require 'twitter'
require 'json'
require 'yaml'

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = ""
  config.consumer_secret     = ""
  config.access_token        = ""
  config.access_token_secret = ""
end

following_list = client.friends('User-exmaple')
begin
  for friend in following_list
    puts friend
  end
rescue Twitter::Error::TooManyRequests => error
  # NOTE: Your process could go to sleep for up to 15 minutes but if you
  # retry any sooner, it will almost certainly fail with the same exception.
  sleep error.rate_limit.reset_in + 1
  retry
end
</code>```

I hope this explains everything, thank you so much.

答:
I solved it by appending screen_name method to friend, example below:

```<code>require 'rubygems'
require 'bundler/setup'

require 'twitter'
require 'json'
require 'yaml'

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = ""
  config.consumer_secret     = ""
  config.access_token        = ""
  config.access_token_secret = ""
end

following_list = client.friends('User-exmaple')
begin
  for friend in following_list
    puts friend.screen_name
  end
rescue Twitter::Error::TooManyRequests => error
  # NOTE: Your process could go to sleep for up to 15 minutes but if you
  # retry any sooner, it will almost certainly fail with the same exception.
  sleep error.rate_limit.reset_in + 1
  retry
end

</code>```

I hope this explains the solution I found.

Body:
I'd love to obtain following list in text (screen names) instead of objects using Twitter Api.  I am new to Ruby programming language and this's my first attempt using api with ruby especially Twitter api. What I expect is list of screen names instead of objects and I will show you examples bellow:

Results I get currently:
current results

Desired and expected results

I've tried methods such as .full_text and .text appended to the objects and didn't get my desired results.I've searched almost everywhere especially here in Stackoverflow and didn't find my answer yet.

This's my code below:

require 'rubygems'
require 'bundler/setup'

require 'twitter'
require 'json'
require 'yaml'

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = ""
  config.consumer_secret     = ""
  config.access_token        = ""
  config.access_token_secret = ""
end

following_list = client.friends('User-exmaple')
begin
  for friend in following_list
    puts friend
  end
rescue Twitter::Error::TooManyRequests => error
  # NOTE: Your process could go to sleep for up to 15 minutes but if you
  # retry any sooner, it will almost certainly fail with the same exception.
  sleep error.rate_limit.reset_in + 1
  retry
end

I hope this explains everything, thank you so much.

Body:
I solved it by appending screen_name method to friend, example below:

require 'rubygems'
require 'bundler/setup'

require 'twitter'
require 'json'
require 'yaml'

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = ""
  config.consumer_secret     = ""
  config.access_token        = ""
  config.access_token_secret = ""
end

following_list = client.friends('User-exmaple')
begin
  for friend in following_list
    puts friend.screen_name
  end
rescue Twitter::Error::TooManyRequests => error
  # NOTE: Your process could go to sleep for up to 15 minutes but if you
  # retry any sooner, it will almost certainly fail with the same exception.
  sleep error.rate_limit.reset_in + 1
  retry
end

I hope this explains the solution I found.


问:
Difference between Avro file format and bz2 compression in hive
I know that below are input and output format in the hive,

Text File.
Sequence File.
RC File.
AVRO File.
ORC File.
Parquet File.

When do we use bz2 compression and how are they different from hive file format? and when to use it?

答:
Avro is a file format and BZ2 is a compression codec. These two are completely different things.

You can chose file format and compression codec independently. Some file formats are using internal compression and have limitation on which codecs can be used. For example ORC supports ZLIB and SNAPPY codecs. And you can configure codec in table properties like this:

```<code>...
STORED AS ORC TBLPROPERTIES ("orc.compress"="SNAPPY")
</code>```

Or using hive configuration:

```<code>hive.exec.orc.default.compress=SNAPPY;
</code>```

Read about ORC here: ORC hive configuration

Avro supports SNAPPY and DEFLATE codecs.

```<code>SET hive.exec.compress.output=true;
SET avro.output.codec=snappy;
</code>```

With textfile you can use any codec.

BZ2 is not the fastest codec and can be used in cases when you do not have strict performance requirements. Read about compression on Cloudera site.

What is important to understand here is that non-splittable compression is not always an issue if you are using splittable container. For example the whole file compressed with snappy is not splittable but ORC using SNAPPY internally is splittable because ORC is splittable.

Body:
Avro is a file format and BZ2 is a compression codec. These two are completely different things.

You can chose file format and compression codec independently. Some file formats are using internal compression and have limitation on which codecs can be used. For example ORC supports ZLIB and SNAPPY codecs. And you can configure codec in table properties like this:

...
STORED AS ORC TBLPROPERTIES ("orc.compress"="SNAPPY")

Or using hive configuration:

hive.exec.orc.default.compress=SNAPPY;

Read about ORC here: ORC hive configuration

Avro supports SNAPPY and DEFLATE codecs.

SET hive.exec.compress.output=true;
SET avro.output.codec=snappy;

With textfile you can use any codec.

BZ2 is not the fastest codec and can be used in cases when you do not have strict performance requirements. Read about compression on Cloudera site.

What is important to understand here is that non-splittable compression is not always an issue if you are using splittable container. For example the whole file compressed with snappy is not splittable but ORC using SNAPPY internally is splittable because ORC is splittable.


问:
Adding a legend to a boxplot in matplotlib/seaborn
I am new to Python.

I have generated a boxplot (with a swarmplot overlay) in matplotlib/seaborn using the following code. I would now like to add a legend that follows the color scheme of each box. Many solutions I find online does not seem to apply to this particular type of graph (eg. only work with grouped boxplots).

When I try to implement the code suggested here I receive the error message.

All input is greatly appreciated!

```<code># Import libraries and modules

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# Set seaborn style.

sns.set(style="whitegrid", palette="colorblind")

# Load summary tidy data.

tidy = pd.read_csv('tidy.csv')

# Define plots for tidy data

fig, ax = plt.subplots(figsize=(10,6))
ax = sns.boxplot(x='header1', y='header2', data=tidy, order=["header1", "header2"])
ax = sns.swarmplot(x="header1", y="header2", data=tidy, color=".25", order=["header1", "header2"])
labels = [item.get_text() for item in ax.get_xticklabels()]
labels[0] = 'header1'
labels[1] = 'header2'
ax.set_xticklabels(labels)
ax.legend(loc='best')
</code>```

Example of the data I am working with.

```<code>Object,Metric,Length
MT1,B2A1,3.57675
MT1,B2A2,2.9474600000000004
MT1,B2A3,2.247772857142857
MT1,B2A4,3.754455
MT1,B2A5,2.716282
MT1,B2A6,2.91325
MT10,B2A1,3.34361
MT10,B2A2,2.889958333333333
MT10,B2A3,2.22087
MT10,B2A4,2.87669
MT10,B2A5,1.6745005555555557
MT12,B2A1,3.3938900000000003
MT12,B2A2,2.00601
MT12,B2A3,2.1720200000000003
MT12,B2A4,2.452923333333333
</code>```

答:
The no handles with labels found to put in the legend error is due to calling ax.legend() while your two artists (boxplot and swarmplot) do not have a label.

sns.boxplot is based on matplotlib's boxplot and sns.swarmplot on scatter, so all you need is to give them respectively a labels and label argument.

```<code>ax = sns.boxplot(..., labels=["Metric", "Length"])
ax = sns.swarmplot(..., label="something goes here")
</code>```

Alternatively, according to this you can leave the seaborn part untouched and fiddle with:

```<code>handles, _ = ax.get_legend_handles_labels()          # Get the artists.
ax.legend(handles, ["label1", "label2"], loc="best") # Associate manually the artists to a label.
</code>```

Body:
I am new to Python.

I have generated a boxplot (with a swarmplot overlay) in matplotlib/seaborn using the following code. I would now like to add a legend that follows the color scheme of each box. Many solutions I find online does not seem to apply to this particular type of graph (eg. only work with grouped boxplots).

When I try to implement the code suggested here I receive the error message.

All input is greatly appreciated!

# Import libraries and modules

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# Set seaborn style.

sns.set(style="whitegrid", palette="colorblind")

# Load summary tidy data.

tidy = pd.read_csv('tidy.csv')

# Define plots for tidy data

fig, ax = plt.subplots(figsize=(10,6))
ax = sns.boxplot(x='header1', y='header2', data=tidy, order=["header1", "header2"])
ax = sns.swarmplot(x="header1", y="header2", data=tidy, color=".25", order=["header1", "header2"])
labels = [item.get_text() for item in ax.get_xticklabels()]
labels[0] = 'header1'
labels[1] = 'header2'
ax.set_xticklabels(labels)
ax.legend(loc='best')

Example of the data I am working with.

Object,Metric,Length
MT1,B2A1,3.57675
MT1,B2A2,2.9474600000000004
MT1,B2A3,2.247772857142857
MT1,B2A4,3.754455
MT1,B2A5,2.716282
MT1,B2A6,2.91325
MT10,B2A1,3.34361
MT10,B2A2,2.889958333333333
MT10,B2A3,2.22087
MT10,B2A4,2.87669
MT10,B2A5,1.6745005555555557
MT12,B2A1,3.3938900000000003
MT12,B2A2,2.00601
MT12,B2A3,2.1720200000000003
MT12,B2A4,2.452923333333333

Body:
The no handles with labels found to put in the legend error is due to calling ax.legend() while your two artists (boxplot and swarmplot) do not have a label.

sns.boxplot is based on matplotlib's boxplot and sns.swarmplot on scatter, so all you need is to give them respectively a labels and label argument.

ax = sns.boxplot(..., labels=["Metric", "Length"])
ax = sns.swarmplot(..., label="something goes here")

Alternatively, according to this you can leave the seaborn part untouched and fiddle with:

handles, _ = ax.get_legend_handles_labels()          # Get the artists.
ax.legend(handles, ["label1", "label2"], loc="best") # Associate manually the artists to a label.


问:
pip doesn't work after upgrade on Python 3.4 (Windows 10). How to downgrade?
I upgraded pip on Python 3.4 to last version (20.1.1) and new pip doesn't work with message

```<code>RuntimeError: Python 3.5 or later is required
</code>```

How to return back old version of pip?

I can't upgrade Python to 3.5 version or more

I can't use a new pip to install old version - my new pip doesn't work at all

Is there any way to uninstall pip?

答:
I found solution. MrFuppes gave good advice but it doesn't work because of get-pip.py file is intended for last version of pip (version 20.1.1). If download old version of this file - all works. Version of pip that goes with Python 3.4 is version 7.1.2.

So go to https://bootstrap.pypa.io/3.2/ and download get-pip.py file. This is an old version of pip (7.1.2). Go to folder where get-pip.py is located and run:

```<code>python get-pip.py pip==7.1.2
</code>```

This uninstall your current version of pip (20.1.1) and setup old version (7.1.2).

Actually this site https://bootstrap.pypa.io/ has some versions of pip - (7.1.2), (9.0.3), (10.0.1), (19.1.1) and (20.1.1) today. I think that other versions before 20.1.1 should work too. Since version 19.1 of pip is last that support Python 3.4.

Body:
I upgraded pip on Python 3.4 to last version (20.1.1) and new pip doesn't work with message

RuntimeError: Python 3.5 or later is required

How to return back old version of pip?

I can't upgrade Python to 3.5 version or more

I can't use a new pip to install old version - my new pip doesn't work at all

Is there any way to uninstall pip?

Body:
I found solution. MrFuppes gave good advice but it doesn't work because of get-pip.py file is intended for last version of pip (version 20.1.1). If download old version of this file - all works. Version of pip that goes with Python 3.4 is version 7.1.2.

So go to https://bootstrap.pypa.io/3.2/ and download get-pip.py file. This is an old version of pip (7.1.2). Go to folder where get-pip.py is located and run:

python get-pip.py pip==7.1.2

This uninstall your current version of pip (20.1.1) and setup old version (7.1.2).

Actually this site https://bootstrap.pypa.io/ has some versions of pip - (7.1.2), (9.0.3), (10.0.1), (19.1.1) and (20.1.1) today. I think that other versions before 20.1.1 should work too. Since version 19.1 of pip is last that support Python 3.4.


问:
adding health check to docker container
I am trying to add a health check to my docker container so in my Dockerfile I added this line

HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1

based loosely on this tutorial: https://howchoo.com/g/zwjhogrkywe/how-to-add-a-health-check-to-your-docker-container . In my docker-compose file I have added the health check line like this:

```<code>    healthcheck:
      test: ["CMD", "curl", "--silent", "--fail", "http://localhost:8080/health"]
</code>```

but the container always reports unhealthy. So if I execute docker exec -it my-container /bin/bash and get inside the container and then execute the health request I get this:

```<code>    $ curl --fail http://localhost:8080/health
    curl: (22) The requested URL returned error: 411 Length Required
</code>```

What am I missing? Nginx is already installed in the container so I would like to simply make that URL with /health work.

答:
I gave up on using the HEALTHCHECK command in Dockerfile and instead I am changing the nginx.conf file by adding

```<code>    location /health {
        access_log off;
        return 200 "healthy\n";
    }
</code>```

docker-compose.yml remains the same.
This works well enough for me.

Title: adding health check to docker container

Body:
I am trying to add a health check to my docker container so in my Dockerfile I added this line

HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1

based loosely on this tutorial: https://howchoo.com/g/zwjhogrkywe/how-to-add-a-health-check-to-your-docker-container . In my docker-compose file I have added the health check line like this:

    healthcheck:
      test: ["CMD", "curl", "--silent", "--fail", "http://localhost:8080/health"]

but the container always reports unhealthy. So if I execute docker exec -it my-container /bin/bash and get inside the container and then execute the health request I get this:

    $ curl --fail http://localhost:8080/health
    curl: (22) The requested URL returned error: 411 Length Required

What am I missing? Nginx is already installed in the container so I would like to simply make that URL with /health work.

Body:
I gave up on using the HEALTHCHECK command in Dockerfile and instead I am changing the nginx.conf file by adding

    location /health {
        access_log off;
        return 200 "healthy\n";
    }

docker-compose.yml remains the same.
This works well enough for me.


问:
"Distinct" results in complex query
I have the following query, which returns all merchants in the database who have transactions between two given dates.

```<code>SELECT distinct me.id, me.merchant_num, me.merchant_nm, count(1) as num_transactions
       ,CASE WHEN me.status = 'A' THEN 'Yes' ELSE 'No' END as production_mode
FROM merchant_t me
LEFT OUTER JOIN transaction_t tt
    ON tt.merchant_id = me.id
    AND tt.transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
WHERE me.status = 'T'
GROUP BY me.id, me.merchant_num, me.merchant_nm, me.status
</code>```

But, there is additional information I need to include in the query. I've written the enhanced query below, but it results in duplicated merchants. I know the query could be written better, but that's the limit of my SQL knowledge.

I need to keep the same number of results as the above query.

```<code>SELECT distinct me.id, me.merchant_num, me.merchant_nm, count(1) as num_transactions
       ,CASE WHEN me.status = 'A' THEN 'Yes' ELSE 'No' END as production_mode

       -- additional information needed as below, with comments

       -- the date of the last transaction that uses IBank (IBA)
       ,(select max(transaction_dt)
           from transaction_t where merchant_id = me.id
           and tt.bank_txt = 'IBA') as last_ibank_transaction

       -- the value of the "trans_live" column for the merchant's most recent transaction
       ,(select top 1 trans_live
           from transaction_t
           where merchant_id = me.id order by transaction_dt desc) is_live
FROM merchant_t me
    LEFT OUTER JOIN transaction_t tt
         ON tt.merchant_id = me.id
         AND tt.transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
    WHERE me.status = 'T'
    GROUP BY me.id, me.merchant_num, me.merchant_nm, me.status, tt.bank_txt
</code>```

This returns duplicated merchants. In the screenshot below, I have filtered on a single merchant to show the duplication. The first result set is from the original query. The second is from the updated query. "DISTINCT" does its job but I only want to see one merchant record.

There are two tables involved:

```<code>merchant_t
----------
id     merchant_num    merchant_nm    status

transaction_t
--------------
id     merchant_id     transaction_dt     trans_live     bank_txt
</code>```

EDIT

I am trying to avoid having the dates inside a subquery

VARUN'S ANSWER

The updated query returns many duplicates as below.

SQL SCRIPT

```USE [XYZ]
GO
/****** Object:  Table [dbo].[merchant_t]    Script Date: 6/10/2020 5:23:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[merchant_t](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [merchant_num] [nvarchar](50) NULL,
    [merchant_nm] [nvarchar](100) NULL,
    [status] [nchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[transaction_t]    Script Date: 6/10/2020 5:23:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[transaction_t](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [merchant_id] [int] NULL,
    [transaction_dt] [datetime] NULL,
    [trans_live] [bit] NULL,
    [bank_txt] [nvarchar](30) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[merchant_t] ON
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (335, N'PriceBusterDVD_NZ_AN', N'Pricebuster NZ ANZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (341, N'T6400050', N'Merco Test Merchant', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (342, N'6400262', N'Musac School Test 1', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (366, N'T6400093', N'Paystation Limited Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (367, N'T6400435', N'PB Technologies Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (374, N'PriceBusterDVD_NZ_BN', N'Pricebuster NZ BNZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (389, N'TAirNewZealandNZ_All', N'Test Air NZ - All', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (390, N'T6400061', N'The Warehouse Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (392, N'T6400246', N'University of Waikato Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (538, N'T6400449', N'NZTA Payments Dev System Testing', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (544, N'T6400447', N'NZTA Tolling Dev System Testing', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (631, N'SS64000475', N'Smeedi Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (729, N'T6400048', N'Marram Community Trust Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (776, N'SS64000665', N'POLi Test Bench', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (936, N'T6400002', N'WorldRemit Test NZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1033, N'SS64005103', N'Ahura Consulting Limited', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1173, N'SS64005386', N'Warehouse Stationery Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1236, N'SS64005423', N'KlickEx Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1435, N'T6400477', N'NZMCA', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1580, N'T6400478', N'2 Degrees Mobile - Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1626, N'SS64006121', N'Property Council New Zealand', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1714, N'SS64006558', N'ServiceFinder.co.nz', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1972, N'T6400480', N'2 Degrees Mobile Accept Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1988, N'T6400484', N'HelloClub Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2011, N'T6400482', N'Horowhenua District Council Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2260, N'SS64008067', N'Success Global', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2274, N'64007479', N'Samsung Electronics New Zealand', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2397, N'SS64008228', N'MyBitcoinSaver.com', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2418, N'6400478', N'Spark Staging', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2441, N'SS64008239', N'Kiwi Petz', N'T')
GO
SET IDENTITY_INSERT [dbo].[merchant_t] OFF
GO
SET IDENTITY_INSERT [dbo].[transaction_t] ON
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215957, 389, CAST(N'2020-04-01T06:55:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215958, 389, CAST(N'2020-04-01T06:56:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215959, 389, CAST(N'2020-04-01T07:06:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215960, 389, CAST(N'2020-04-01T07:09:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215961, 389, CAST(N'2020-04-01T08:19:28.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215962, 389, CAST(N'2020-04-01T08:19:45.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215963, 389, CAST(N'2020-04-01T08:19:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215964, 389, CAST(N'2020-04-01T08:20:16.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215965, 389, CAST(N'2020-04-01T09:33:40.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215966, 389, CAST(N'2020-04-01T09:33:46.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215967, 389, CAST(N'2020-04-01T11:05:35.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215968, 389, CAST(N'2020-04-01T11:06:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215969, 389, CAST(N'2020-04-01T11:12:51.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215970, 389, CAST(N'2020-04-01T11:17:38.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215971, 389, CAST(N'2020-04-01T12:45:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215972, 389, CAST(N'2020-04-01T12:45:49.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215973, 389, CAST(N'2020-04-01T12:50:17.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18201776, 1580, CAST(N'2020-04-01T14:16:38.000' AS DateTime), 0, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215974, 389, CAST(N'2020-04-01T12:59:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215975, 389, CAST(N'2020-04-01T14:18:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215976, 389, CAST(N'2020-04-01T14:18:21.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215977, 389, CAST(N'2020-04-01T14:26:15.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215978, 389, CAST(N'2020-04-01T14:33:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215979, 389, CAST(N'2020-04-01T15:12:43.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215980, 389, CAST(N'2020-04-01T15:12:46.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215981, 389, CAST(N'2020-04-01T15:41:14.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215982, 389, CAST(N'2020-04-01T15:43:53.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18223719, 2441, CAST(N'2020-04-02T10:20:03.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231457, 389, CAST(N'2020-04-02T07:11:32.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231458, 389, CAST(N'2020-04-02T07:13:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231459, 389, CAST(N'2020-04-02T08:49:33.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231460, 389, CAST(N'2020-04-02T09:03:17.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231461, 389, CAST(N'2020-04-02T09:08:39.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231462, 389, CAST(N'2020-04-02T11:17:25.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231463, 389, CAST(N'2020-04-02T11:20:53.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231464, 389, CAST(N'2020-04-02T11:22:38.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231465, 389, CAST(N'2020-04-02T12:03:20.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231466, 389, CAST(N'2020-04-02T12:03:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231467, 389, CAST(N'2020-04-02T12:20:27.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231468, 389, CAST(N'2020-04-02T12:37:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18233881, 341, CAST(N'2020-04-02T13:54:30.000' AS DateTime), 0, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18237848, 2011, CAST(N'2020-04-03T13:31:36.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245130, 389, CAST(N'2020-04-03T06:24:34.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245131, 389, CAST(N'2020-04-03T06:26:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245132, 389, CAST(N'2020-04-03T10:55:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245133, 389, CAST(N'2020-04-03T11:00:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245134, 389, CAST(N'2020-04-03T11:00:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245135, 389, CAST(N'2020-04-03T14:01:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245136, 389, CAST(N'2020-04-03T14:08:48.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245137, 389, CAST(N'2020-04-03T14:41:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245138, 389, CAST(N'2020-04-03T14:44:40.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18250367, 2441, CAST(N'2020-04-04T09:53:19.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18274546, 2274, CAST(N'2020-04-06T02:50:01.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18274563, 1714, CAST(N'2020-04-06T06:36:45.000' AS DateTime), 1, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277532, 389, CAST(N'2020-04-06T06:37:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277533, 389, CAST(N'2020-04-06T06:46:45.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277534, 389, CAST(N'2020-04-06T07:36:29.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277535, 389, CAST(N'2020-04-06T07:43:00.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277536, 389, CAST(N'2020-04-06T08:11:22.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277537, 389, CAST(N'2020-04-06T08:12:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18279767, 341, CAST(N'2020-04-06T09:40:12.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18268407, 1033, CAST(N'2020-04-06T20:15:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270264, 544, CAST(N'2020-04-06T12:36:12.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270265, 544, CAST(N'2020-04-06T12:37:11.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270266, 544, CAST(N'2020-04-06T12:38:08.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270267, 544, CAST(N'2020-04-06T12:40:05.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270268, 544, CAST(N'2020-04-06T12:42:50.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270269, 544, CAST(N'2020-04-06T12:43:36.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270270, 544, CAST(N'2020-04-06T12:45:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270271, 544, CAST(N'2020-04-06T12:45:26.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18273055, 538, CAST(N'2020-04-06T12:34:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277538, 389, CAST(N'2020-04-06T11:30:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277539, 389, CAST(N'2020-04-06T11:31:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277540, 389, CAST(N'2020-04-06T11:44:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277541, 389, CAST(N'2020-04-06T11:49:43.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277542, 389, CAST(N'2020-04-06T13:07:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277543, 389, CAST(N'2020-04-06T13:08:50.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277544, 389, CAST(N'2020-04-06T14:10:14.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277545, 389, CAST(N'2020-04-06T14:10:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277546, 389, CAST(N'2020-04-06T14:10:54.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277547, 389, CAST(N'2020-04-06T14:14:26.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277548, 389, CAST(N'2020-04-06T15:25:39.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277549, 389, CAST(N'2020-04-06T15:26:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277550, 389, CAST(N'2020-04-06T18:31:10.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277551, 389, CAST(N'2020-04-06T18:33:05.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277552, 389, CAST(N'2020-04-06T18:44:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277553, 389, CAST(N'2020-04-06T19:46:52.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277554, 389, CAST(N'2020-04-06T20:31:33.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277555, 389, CAST(N'2020-04-06T20:43:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277556, 389, CAST(N'2020-04-06T20:51:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277557, 389, CAST(N'2020-04-06T21:03:01.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18293723, 389, CAST(N'2020-04-07T06:20:15.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18293724, 389, CAST(N'2020-04-07T06:45:17.000' AS DateTime), 0, N'IBA')
GO
```

<h2>LATEST VERSION RESULTS</h2>

<p><img src="https://i.stack.imgur.com/zk40m.png" alt="enter image description here"></p>

<h2>INDEXES</h2>

<h2>merchant_t</h2>

```/****** Object:  Index [PK_merchant_t]    Script Date: 6/13/2020 8:40:44 PM ******/
ALTER TABLE [dbo].[merchant_t] ADD  CONSTRAINT [PK_merchant_t] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_status]    Script Date: 6/13/2020 8:44:08 PM ******/
CREATE NONCLUSTERED INDEX [IX_status] ON [dbo].[merchant_t]
(
    [status] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
```

<h2>transaction_t</h2>

```/****** Object:  Index [IX_merchant_id]    Script Date: 6/13/2020 8:48:08 PM ******/
CREATE NONCLUSTERED INDEX [IX_merchant_id] ON [dbo].[transaction_t]
(
    [merchant_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_transaction_dt]    Script Date: 6/13/2020 8:45:59 PM ******/
CREATE NONCLUSTERED INDEX [IX_transaction_dt] ON [dbo].[transaction_t]
(
    [transaction_dt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_trans_live]    Script Date: 6/13/2020 8:46:57 PM ******/
CREATE NONCLUSTERED INDEX [IX_trans_live] ON [dbo].[transaction_t]
(
    [trans_live] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_merchant_id]    Script Date: 6/13/2020 8:47:17 PM ******/
CREATE NONCLUSTERED INDEX [IX_merchant_id] ON [dbo].[transaction_t]
(
    [merchant_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_bank_txt]    Script Date: 6/13/2020 8:47:37 PM ******/
CREATE NONCLUSTERED INDEX [IX_bank_txt] ON [dbo].[transaction_t]
(
    [bank_txt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
```

答:
The first query is Wrong:
When you are aggregating, you can not leave out a dimension. if you are selecting it, you have to group by it also.

If you are sure you need just 1 record per merchant (612 records) consider moving production_mode to 2 different columns

Here is an optimized query:

```<code>select me.id, me.merchant_num, me.merchant_nm
        , count(*) as num_transactions
        ,sum(CASE WHEN me.status = 'A' THEN 1 ELSE 0 END) as production_mode
        ,sum(CASE WHEN me.status <> 'A' THEN 1 ELSE 0 END) as not_production
        ,max(transaction_dt) as last_ibank_transaction
        ,max(case when trans_rnk = 1 then trans_live else null end) as trans_live
       from
        (
            select * , rank() over (partition by merchant_id order by transaction_dt desc) as trans_rnk
            from transaction_t
        )aa
        left join merchant_t bb on aa.merchant_id=bb.id
        where bank_txt = 'IBA' and transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
       GROUP BY me.id, me.merchant_num, me.merchant_nm
</code>```

Title: "Distinct" results in complex query

Body:
I have the following query, which returns all merchants in the database who have transactions between two given dates.

SELECT distinct me.id, me.merchant_num, me.merchant_nm, count(1) as num_transactions
       ,CASE WHEN me.status = 'A' THEN 'Yes' ELSE 'No' END as production_mode
FROM merchant_t me
LEFT OUTER JOIN transaction_t tt
    ON tt.merchant_id = me.id
    AND tt.transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
WHERE me.status = 'T'
GROUP BY me.id, me.merchant_num, me.merchant_nm, me.status

But, there is additional information I need to include in the query. I've written the enhanced query below, but it results in duplicated merchants. I know the query could be written better, but that's the limit of my SQL knowledge.

I need to keep the same number of results as the above query.

SELECT distinct me.id, me.merchant_num, me.merchant_nm, count(1) as num_transactions
       ,CASE WHEN me.status = 'A' THEN 'Yes' ELSE 'No' END as production_mode

       -- additional information needed as below, with comments

       -- the date of the last transaction that uses IBank (IBA)
       ,(select max(transaction_dt)
           from transaction_t where merchant_id = me.id
           and tt.bank_txt = 'IBA') as last_ibank_transaction

       -- the value of the "trans_live" column for the merchant's most recent transaction
       ,(select top 1 trans_live
           from transaction_t
           where merchant_id = me.id order by transaction_dt desc) is_live
FROM merchant_t me
    LEFT OUTER JOIN transaction_t tt
         ON tt.merchant_id = me.id
         AND tt.transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
    WHERE me.status = 'T'
    GROUP BY me.id, me.merchant_num, me.merchant_nm, me.status, tt.bank_txt

This returns duplicated merchants. In the screenshot below, I have filtered on a single merchant to show the duplication. The first result set is from the original query. The second is from the updated query. "DISTINCT" does its job but I only want to see one merchant record.

There are two tables involved:

merchant_t
----------
id     merchant_num    merchant_nm    status

transaction_t
--------------
id     merchant_id     transaction_dt     trans_live     bank_txt

EDIT

I am trying to avoid having the dates inside a subquery

VARUN'S ANSWER

The updated query returns many duplicates as below.

SQL SCRIPT

USE [XYZ]
GO
/****** Object:  Table [dbo].[merchant_t]    Script Date: 6/10/2020 5:23:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[merchant_t](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [merchant_num] [nvarchar](50) NULL,
    [merchant_nm] [nvarchar](100) NULL,
    [status] [nchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[transaction_t]    Script Date: 6/10/2020 5:23:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[transaction_t](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [merchant_id] [int] NULL,
    [transaction_dt] [datetime] NULL,
    [trans_live] [bit] NULL,
    [bank_txt] [nvarchar](30) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[merchant_t] ON
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (335, N'PriceBusterDVD_NZ_AN', N'Pricebuster NZ ANZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (341, N'T6400050', N'Merco Test Merchant', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (342, N'6400262', N'Musac School Test 1', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (366, N'T6400093', N'Paystation Limited Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (367, N'T6400435', N'PB Technologies Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (374, N'PriceBusterDVD_NZ_BN', N'Pricebuster NZ BNZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (389, N'TAirNewZealandNZ_All', N'Test Air NZ - All', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (390, N'T6400061', N'The Warehouse Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (392, N'T6400246', N'University of Waikato Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (538, N'T6400449', N'NZTA Payments Dev System Testing', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (544, N'T6400447', N'NZTA Tolling Dev System Testing', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (631, N'SS64000475', N'Smeedi Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (729, N'T6400048', N'Marram Community Trust Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (776, N'SS64000665', N'POLi Test Bench', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (936, N'T6400002', N'WorldRemit Test NZ', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1033, N'SS64005103', N'Ahura Consulting Limited', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1173, N'SS64005386', N'Warehouse Stationery Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1236, N'SS64005423', N'KlickEx Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1435, N'T6400477', N'NZMCA', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1580, N'T6400478', N'2 Degrees Mobile - Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1626, N'SS64006121', N'Property Council New Zealand', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1714, N'SS64006558', N'ServiceFinder.co.nz', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1972, N'T6400480', N'2 Degrees Mobile Accept Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (1988, N'T6400484', N'HelloClub Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2011, N'T6400482', N'Horowhenua District Council Test', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2260, N'SS64008067', N'Success Global', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2274, N'64007479', N'Samsung Electronics New Zealand', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2397, N'SS64008228', N'MyBitcoinSaver.com', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2418, N'6400478', N'Spark Staging', N'T')
GO
INSERT [dbo].[merchant_t] ([id], [merchant_num], [merchant_nm], [status]) VALUES (2441, N'SS64008239', N'Kiwi Petz', N'T')
GO
SET IDENTITY_INSERT [dbo].[merchant_t] OFF
GO
SET IDENTITY_INSERT [dbo].[transaction_t] ON
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215957, 389, CAST(N'2020-04-01T06:55:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215958, 389, CAST(N'2020-04-01T06:56:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215959, 389, CAST(N'2020-04-01T07:06:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215960, 389, CAST(N'2020-04-01T07:09:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215961, 389, CAST(N'2020-04-01T08:19:28.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215962, 389, CAST(N'2020-04-01T08:19:45.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215963, 389, CAST(N'2020-04-01T08:19:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215964, 389, CAST(N'2020-04-01T08:20:16.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215965, 389, CAST(N'2020-04-01T09:33:40.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215966, 389, CAST(N'2020-04-01T09:33:46.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215967, 389, CAST(N'2020-04-01T11:05:35.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215968, 389, CAST(N'2020-04-01T11:06:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215969, 389, CAST(N'2020-04-01T11:12:51.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215970, 389, CAST(N'2020-04-01T11:17:38.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215971, 389, CAST(N'2020-04-01T12:45:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215972, 389, CAST(N'2020-04-01T12:45:49.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215973, 389, CAST(N'2020-04-01T12:50:17.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18201776, 1580, CAST(N'2020-04-01T14:16:38.000' AS DateTime), 0, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215974, 389, CAST(N'2020-04-01T12:59:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215975, 389, CAST(N'2020-04-01T14:18:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215976, 389, CAST(N'2020-04-01T14:18:21.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215977, 389, CAST(N'2020-04-01T14:26:15.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215978, 389, CAST(N'2020-04-01T14:33:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215979, 389, CAST(N'2020-04-01T15:12:43.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215980, 389, CAST(N'2020-04-01T15:12:46.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215981, 389, CAST(N'2020-04-01T15:41:14.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18215982, 389, CAST(N'2020-04-01T15:43:53.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18223719, 2441, CAST(N'2020-04-02T10:20:03.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231457, 389, CAST(N'2020-04-02T07:11:32.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231458, 389, CAST(N'2020-04-02T07:13:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231459, 389, CAST(N'2020-04-02T08:49:33.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231460, 389, CAST(N'2020-04-02T09:03:17.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231461, 389, CAST(N'2020-04-02T09:08:39.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231462, 389, CAST(N'2020-04-02T11:17:25.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231463, 389, CAST(N'2020-04-02T11:20:53.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231464, 389, CAST(N'2020-04-02T11:22:38.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231465, 389, CAST(N'2020-04-02T12:03:20.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231466, 389, CAST(N'2020-04-02T12:03:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231467, 389, CAST(N'2020-04-02T12:20:27.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18231468, 389, CAST(N'2020-04-02T12:37:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18233881, 341, CAST(N'2020-04-02T13:54:30.000' AS DateTime), 0, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18237848, 2011, CAST(N'2020-04-03T13:31:36.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245130, 389, CAST(N'2020-04-03T06:24:34.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245131, 389, CAST(N'2020-04-03T06:26:47.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245132, 389, CAST(N'2020-04-03T10:55:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245133, 389, CAST(N'2020-04-03T11:00:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245134, 389, CAST(N'2020-04-03T11:00:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245135, 389, CAST(N'2020-04-03T14:01:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245136, 389, CAST(N'2020-04-03T14:08:48.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245137, 389, CAST(N'2020-04-03T14:41:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18245138, 389, CAST(N'2020-04-03T14:44:40.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18250367, 2441, CAST(N'2020-04-04T09:53:19.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18274546, 2274, CAST(N'2020-04-06T02:50:01.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18274563, 1714, CAST(N'2020-04-06T06:36:45.000' AS DateTime), 1, N'ANZ')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277532, 389, CAST(N'2020-04-06T06:37:57.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277533, 389, CAST(N'2020-04-06T06:46:45.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277534, 389, CAST(N'2020-04-06T07:36:29.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277535, 389, CAST(N'2020-04-06T07:43:00.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277536, 389, CAST(N'2020-04-06T08:11:22.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277537, 389, CAST(N'2020-04-06T08:12:13.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18279767, 341, CAST(N'2020-04-06T09:40:12.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18268407, 1033, CAST(N'2020-04-06T20:15:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270264, 544, CAST(N'2020-04-06T12:36:12.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270265, 544, CAST(N'2020-04-06T12:37:11.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270266, 544, CAST(N'2020-04-06T12:38:08.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270267, 544, CAST(N'2020-04-06T12:40:05.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270268, 544, CAST(N'2020-04-06T12:42:50.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270269, 544, CAST(N'2020-04-06T12:43:36.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270270, 544, CAST(N'2020-04-06T12:45:09.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18270271, 544, CAST(N'2020-04-06T12:45:26.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18273055, 538, CAST(N'2020-04-06T12:34:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277538, 389, CAST(N'2020-04-06T11:30:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277539, 389, CAST(N'2020-04-06T11:31:06.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277540, 389, CAST(N'2020-04-06T11:44:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277541, 389, CAST(N'2020-04-06T11:49:43.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277542, 389, CAST(N'2020-04-06T13:07:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277543, 389, CAST(N'2020-04-06T13:08:50.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277544, 389, CAST(N'2020-04-06T14:10:14.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277545, 389, CAST(N'2020-04-06T14:10:37.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277546, 389, CAST(N'2020-04-06T14:10:54.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277547, 389, CAST(N'2020-04-06T14:14:26.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277548, 389, CAST(N'2020-04-06T15:25:39.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277549, 389, CAST(N'2020-04-06T15:26:02.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277550, 389, CAST(N'2020-04-06T18:31:10.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277551, 389, CAST(N'2020-04-06T18:33:05.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277552, 389, CAST(N'2020-04-06T18:44:58.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277553, 389, CAST(N'2020-04-06T19:46:52.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277554, 389, CAST(N'2020-04-06T20:31:33.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277555, 389, CAST(N'2020-04-06T20:43:56.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277556, 389, CAST(N'2020-04-06T20:51:42.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18277557, 389, CAST(N'2020-04-06T21:03:01.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18293723, 389, CAST(N'2020-04-07T06:20:15.000' AS DateTime), 0, N'IBA')
GO
INSERT [dbo].[transaction_t] ([id], [merchant_id], [transaction_dt], [trans_live], [bank_txt]) VALUES (18293724, 389, CAST(N'2020-04-07T06:45:17.000' AS DateTime), 0, N'IBA')
GO

LATEST VERSION RESULTS

INDEXES

merchant_t

/****** Object:  Index [PK_merchant_t]    Script Date: 6/13/2020 8:40:44 PM ******/
ALTER TABLE [dbo].[merchant_t] ADD  CONSTRAINT [PK_merchant_t] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_status]    Script Date: 6/13/2020 8:44:08 PM ******/
CREATE NONCLUSTERED INDEX [IX_status] ON [dbo].[merchant_t]
(
    [status] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

transaction_t

/****** Object:  Index [IX_merchant_id]    Script Date: 6/13/2020 8:48:08 PM ******/
CREATE NONCLUSTERED INDEX [IX_merchant_id] ON [dbo].[transaction_t]
(
    [merchant_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_transaction_dt]    Script Date: 6/13/2020 8:45:59 PM ******/
CREATE NONCLUSTERED INDEX [IX_transaction_dt] ON [dbo].[transaction_t]
(
    [transaction_dt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_trans_live]    Script Date: 6/13/2020 8:46:57 PM ******/
CREATE NONCLUSTERED INDEX [IX_trans_live] ON [dbo].[transaction_t]
(
    [trans_live] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_merchant_id]    Script Date: 6/13/2020 8:47:17 PM ******/
CREATE NONCLUSTERED INDEX [IX_merchant_id] ON [dbo].[transaction_t]
(
    [merchant_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

/****** Object:  Index [IX_bank_txt]    Script Date: 6/13/2020 8:47:37 PM ******/
CREATE NONCLUSTERED INDEX [IX_bank_txt] ON [dbo].[transaction_t]
(
    [bank_txt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

Body:
The first query is Wrong:
When you are aggregating, you can not leave out a dimension. if you are selecting it, you have to group by it also.

If you are sure you need just 1 record per merchant (612 records) consider moving production_mode to 2 different columns

Here is an optimized query:

select me.id, me.merchant_num, me.merchant_nm
        , count(*) as num_transactions
        ,sum(CASE WHEN me.status = 'A' THEN 1 ELSE 0 END) as production_mode
        ,sum(CASE WHEN me.status <> 'A' THEN 1 ELSE 0 END) as not_production
        ,max(transaction_dt) as last_ibank_transaction
        ,max(case when trans_rnk = 1 then trans_live else null end) as trans_live
       from
        (
            select * , rank() over (partition by merchant_id order by transaction_dt desc) as trans_rnk
            from transaction_t
        )aa
        left join merchant_t bb on aa.merchant_id=bb.id
        where bank_txt = 'IBA' and transaction_dt BETWEEN '2020-04-01' and '2020-04-30'
       GROUP BY me.id, me.merchant_num, me.merchant_nm


问:
WebSphere Portal 6.1 theme localization
How can a theme for a portal be localized? Suppose I wanted some text in

IBM\WebSphere\wp_profile\installedApps\lhept\wps.ear\wps.war\themes\html\<theme name>\footer.jspf

to be different depending on locale.

It seems that I am looking for something similar to <portal-fmt:text key="link.main.menu" bundle="nls.engine"/>", but I cannot locate the properties bundle file nls.engine, to add my own key-value pairs.

答:
In version 6.1, properties are located in ..\WebSphere\PortalServer\ui\wp.ui\shared\app\wp.ui.jar file.

When one wants to change the translations or add additional keys:

the appropriate .properties file should be extracted to or

a new .properties file should be created in

..\WebSphere\PortalServer\shared\app\nls directory (which is originally empty). The desired key-value pairs are entered in the extracted or newly-created .properties file.

Finally, the portal server must be restarted.

ContentLicense: CC BY-SA 3.0

Title: WebSphere Portal 6.1 theme localization


问:
date_trunc interval in PostgreSQL 15 minutes
```<code>const string query = "SELECT worker, date_trunc('hour', created) AS created, AVG(hashrate) AS hashrate, " + "AVG(sharespersecond) AS sharespersecond FROM minerstats " +
"WHERE poolid = @poolId AND miner = @miner AND created >= @start AND created <= @end " +
"GROUP BY date_trunc('hour', created), worker " +
"ORDER BY created, worker;";
</code>```

This query displays the time periods of hours.
how to make 15 minutes?

答:
Here is one option:</p>

```<code>date_trunc('hour', created)
    + extract(minute from created)::int / 15 * interval '15' minute
</code>```

Body:
const string query = "SELECT worker, date_trunc('hour', created) AS created, AVG(hashrate) AS hashrate, " + "AVG(sharespersecond) AS sharespersecond FROM minerstats " +
"WHERE poolid = @poolId AND miner = @miner AND created >= @start AND created <= @end " +
"GROUP BY date_trunc('hour', created), worker " +
"ORDER BY created, worker;";

This query displays the time periods of hours.
how to make 15 minutes?

Body:
Here is one option:

date_trunc('hour', created)
    + extract(minute from created)::int / 15 * interval '15' minute


问:
Django management command doesn't flush stdout
I'm trying to print to console before and after processing that takes a while in a Django management command, like this:

```<code>import requests
import xmltodict

from django.core.management.base import BaseCommand

def get_all_routes():
    url = 'http://busopen.jeju.go.kr/OpenAPI/service/bis/Bus'

    r = requests.get(url)
    data = xmltodict.parse(r.content)

    return data['response']['body']['items']['item']

class Command(BaseCommand):

    help = 'Updates the database via Bus Info API'

    def handle(self, *args, **options):
        self.stdout.write('Saving routes ... ', ending='')
        for route in get_all_routes():
            route_obj = Route(
                route_type=route['routeTp'], route_id=route['routeId'], route_number=route['routeNum'])
            route_obj.save()
        self.stdout.write('done.')
</code>```

In the above code, Saving routes ... is expected to print before the loop begins, and done. right next to it when the loop completes so that it looks like Saving routes ... done. in the end.

However, the former doesn't print until the loop completes, when both strings finally print at the same time, which is not what I expected.

I found this question, where the answer suggests flushing the output i.e. self.stdout.flush(), so I added that to my code:

```<code>    def handle(self, *args, **options):
        self.stdout.write('Saving routes ... ', ending='')
        self.stdout.flush()
        for route in get_all_routes():
            route_obj = Route(
                route_type=route['routeTp'], route_id=route['routeId'], route_number=route['routeNum'])
            route_obj.save()
        self.stdout.write('done.')
</code>```

Still, the result remains unchanged.

What could have I done wrong?

答: Have you try to set PYTHONUNBUFFERED environment variable? </p>

Body:
I'm trying to print to console before and after processing that takes a while in a Django management command, like this:

import requests
import xmltodict

from django.core.management.base import BaseCommand

def get_all_routes():
    url = 'http://busopen.jeju.go.kr/OpenAPI/service/bis/Bus'

    r = requests.get(url)
    data = xmltodict.parse(r.content)

    return data['response']['body']['items']['item']

class Command(BaseCommand):

    help = 'Updates the database via Bus Info API'

    def handle(self, *args, **options):
        self.stdout.write('Saving routes ... ', ending='')
        for route in get_all_routes():
            route_obj = Route(
                route_type=route['routeTp'], route_id=route['routeId'], route_number=route['routeNum'])
            route_obj.save()
        self.stdout.write('done.')

In the above code, Saving routes ... is expected to print before the loop begins, and done. right next to it when the loop completes so that it looks like Saving routes ... done. in the end.

However, the former doesn't print until the loop completes, when both strings finally print at the same time, which is not what I expected.

I found this question, where the answer suggests flushing the output i.e. self.stdout.flush(), so I added that to my code:

    def handle(self, *args, **options):
        self.stdout.write('Saving routes ... ', ending='')
        self.stdout.flush()
        for route in get_all_routes():
            route_obj = Route(
                route_type=route['routeTp'], route_id=route['routeId'], route_number=route['routeNum'])
            route_obj.save()
        self.stdout.write('done.')

Still, the result remains unchanged.

What could have I done wrong?


问:
Force line break after first word in a div in React component
I am working with a
 where data comes as simple text from an outer source. For instance
Business in three different continents.
 . Now I need to show this text like below:

```<code>         Business

in four different countries
</code>```

Must have: text-align: center; and line break always after the first word only.

Problem Since I have only one HTML element as in
 to work with I can not add \n inside the
 content. This would only either be after or before the entire line of text if I use pseudo element &::before / &::after (for the @emotion/styled I am using) and not after the first word. Since CSS can't count words it seems this issue can not be solved with CSS only. Also the
 container width has to adjust to the second line, hence I can't use display:block because it will be applied to the entire line of text. Saw in other posts to add two white spaces to force line break but this can't be done just after first word since I don't have any nested HTML element, like

Btw, can react-markdown help?

What is the best way to solve this problem?

答:
Why not use JS to break the string into two parts?</p>

```<code>var sentence = "Business in three different continents.";
var firstWhiteSpace = sentence.indexOf(" ");
var firstWord = sentence.substr(0, firstWhiteSpace);
var restOfSentence = sentence.substr(firstWhiteSpace+1);

// Then you can use different divs for the first word and the rest of the
// sentence and style then individually.
<div>firstWord</div>
<div>restOfSentence</div>
</code>```

Body:
I am working with a
 where data comes as simple text from an outer source. For instance
Business in three different continents.
 . Now I need to show this text like below:

         Business

in four different countries

Must have: text-align: center; and line break always after the first word only.

Problem Since I have only one HTML element as in
 to work with I can not add \n inside the
 content. This would only either be after or before the entire line of text if I use pseudo element &::before / &::after (for the @emotion/styled I am using) and not after the first word. Since CSS can't count words it seems this issue can not be solved with CSS only. Also the
 container width has to adjust to the second line, hence I can't use display:block because it will be applied to the entire line of text. Saw in other posts to add two white spaces to force line break but this can't be done just after first word since I don't have any nested HTML element, like

Btw, can react-markdown help?

What is the best way to solve this problem?

Body:
Why not use JS to break the string into two parts?

var sentence = "Business in three different continents.";
var firstWhiteSpace = sentence.indexOf(" ");
var firstWord = sentence.substr(0, firstWhiteSpace);
var restOfSentence = sentence.substr(firstWhiteSpace+1);

// Then you can use different divs for the first word and the rest of the
// sentence and style then individually.
<div>firstWord</div>
<div>restOfSentence</div>


问:
Gradle dependencies: compile using local jar vs compile from maven repository?
Let's say I have 2 projects: utils-project, main-project.
It works fine when I use in main-project build.gradle dependency from my maven repository:

```<code>dependencies {
    compile 'my.group:utils-project:some-version'
}
</code>```

When I download jar from maven and add jar file to build.gradle it fails due to missing utils-project transitive dependencies:

```<code>dependencies {
    compile files('/path/to/jar/file/utils-project.some-version.jar')
}
</code>```

How is it different and how can I achieve the same effect when compiling my main-project using local jar?

答:
The difference is the Project Object Model (POM), its presence or absence. The POM file pom.xml contains the dependencies of a particular module and is usually deployed with the project artifacts to a Maven repository.

When you say compile files(), Gradle has only access to the artifact. Since the POM is absent, dependency information is not available and the build is likely to fail. In contrast, when declaring dependencies resolved from a proper repository, Gradle fetches the POM before downloading the actual artifact and its dependencies and transitive dependencies.

You can achieve the same effect with local jars by

Downloading all dependencies and transitive dependencies (and so on) to a local folder and reference them accordingly

```<code>compile files('/path/to/jar/file/*.jar')
</code>```

Use flat directory repositories

Create a uber/fat/shaded/shadow of the particular library so that it includes all dependencies in a single jar file.

Body:
Let's say I have 2 projects: utils-project, main-project.
It works fine when I use in main-project build.gradle dependency from my maven repository:

dependencies {
    compile 'my.group:utils-project:some-version'
}

When I download jar from maven and add jar file to build.gradle it fails due to missing utils-project transitive dependencies:

dependencies {
    compile files('/path/to/jar/file/utils-project.some-version.jar')
}

How is it different and how can I achieve the same effect when compiling my main-project using local jar?

Body:
The difference is the Project Object Model (POM), its presence or absence. The POM file pom.xml contains the dependencies of a particular module and is usually deployed with the project artifacts to a Maven repository.

When you say compile files(), Gradle has only access to the artifact. Since the POM is absent, dependency information is not available and the build is likely to fail. In contrast, when declaring dependencies resolved from a proper repository, Gradle fetches the POM before downloading the actual artifact and its dependencies and transitive dependencies.

You can achieve the same effect with local jars by

Downloading all dependencies and transitive dependencies (and so on) to a local folder and reference them accordingly

compile files('/path/to/jar/file/*.jar')

Use flat directory repositories

Create a uber/fat/shaded/shadow of the particular library so that it includes all dependencies in a single jar file.


问:
How can I unit test a form containing ng-select?
I have created an Angular form component that uses <ng-select> as a replacement for HTML <select> elements.  Now I want to unit test my component.  To test the component logic I have methods that find HTML elements in the DOM and examine or modify their value.  This works fine with native HTML elements.  But <ng-select> is difficult.

I can find the current value with something like this, but it feels like a very brittle solution.

```<code>document.querySelector("ng-select[formControlName=country] .ng-value .ng-value-label").innerText
</code>```

And how do I change the selection?  With a standard input component you can set the value, then fire an input event. There's an <input type="text" role="combobox"> inside <ng-select/>, but changing its value doesn't seem to affect the FormControl value.

I'm not trying to test ng-select, but I do need to verify that my component reacts appropriately to selection changes.  It will also be necessary to make selections in the UI when running automated integration tests.

答: The answer is to check out the ng-select source and look at the test code.  There are several examples of tests that change select values.</p>

Body:
I have created an Angular form component that uses <ng-select> as a replacement for HTML <select> elements.  Now I want to unit test my component.  To test the component logic I have methods that find HTML elements in the DOM and examine or modify their value.  This works fine with native HTML elements.  But <ng-select> is difficult.

I can find the current value with something like this, but it feels like a very brittle solution.

document.querySelector("ng-select[formControlName=country] .ng-value .ng-value-label").innerText

And how do I change the selection?  With a standard input component you can set the value, then fire an input event. There's an <input type="text" role="combobox"> inside <ng-select/>, but changing its value doesn't seem to affect the FormControl value.

I'm not trying to test ng-select, but I do need to verify that my component reacts appropriately to selection changes.  It will also be necessary to make selections in the UI when running automated integration tests.


问:
How do i map multiple left outer joins to inherited objects with dapper?
I'm using Dapper and I am trying to produce a list with 3 classes, 2 inherited and a base class . These classes are:

```<code>public class Cow
{
    public int Id { get; set; }
    public string Name { get; set; }
}
public class Steak: Cow
{
    public int DonenessId { get; set; }
}
public class Jerky: Cow
{
    public int MarinadeId { get; set; }
}
</code>```

My stored procedure doesn't have any parameters and uses left outer joins:

```<code>SELECT *  FROM Cow c
LEFT OUTER JOIN dbo.Jerky j ON j.CowId = c.Id
LEFT OUTER JOIN dbo.Steak s ON s.CowId = c.Id
</code>```

=

```<code>+----+----------+------+-------+------------+------+-------+------------+
| Id | Name     | Id   | CowId | MarinadeId | Id   | CowId | DonenessId |
+-----------------------------------------------------------------------+
| 1  | Artricia | NULL | NULL  | NULL       | 21   |   1   | 5          |
+-----------------------------------------------------------------------+
| 2  | Betty    | 13   | 2     | 3          | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 3  | Cindy    | 14   | 3     | 1          | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 4  | Denile   | NULL | NULL  | NULL       | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 5  | Enid     | NULL | NULL  | NULL       | 22   | 5     | 3          |
+----+----------+------+-------+------------+------+-------+------------+
</code>```

I'm trying to produce a list of Cow objects so I can loop through them, I need to use Dapper for my organisation and I need it in one stored procedure.

From the above results I'm looking to achieve a list of 5 Cow Objects where 2 can be casted as Steak and 2 can be casted as Jerky.

Edit: Refined what I'm asking for.

I'm stuck because I don't know what to put in the map: argument of the query. Additionally should the type be , or ?

答:
I have solved my problem, instead of deleting the question I'll leave the answer here because it took alot of bashing and i worked hard on this beef abstraction for y'all.

Firstly, the result set of the stored procedure has to have better names for the columns.

```<code>SELECT
c.Id AS Id,
c.Name AS Name,
j.Id AS JerkyId,
j.MarinadeId AS JerkyMarinadeId,
s.Id AS SteakId,
s.DonenessId AS SteakDonenessId
FROM Cow c
LEFT OUTER JOIN dbo.Jerky j ON j.CowId = c.Id
LEFT OUTER JOIN dbo.Steak s ON s.CowId = c.Id
</code>```

Since there are now uniquely named columns which seperate the joins, we can splitOn:

```<code>var lookup = new Dictionary<int, Cow>();
_dbConnection.Query<Cow, Jerky, Steak, Cow>(QueryConstants.MeatDetective,
    (c, j, s) =>
    {
        Cow cow;
        if (!lookup.TryGetValue(c.Id, out cow))
        {
            if (s != null)
            {
                s.Id = c.Id;
                s.Name = c.Name;
                lookup.Add(c.Id, s);
            }
            else if (j != null)
            {
                j.Id = c.Id;
                j.Name = c.Name;
                lookup.Add(c.Id, j);
            }
            else
            {
                lookup.Add(c.Id, c);
            }
        }

        return cow;
    }, splitOn: "JerkyId,SteakId");
    var beef = lookup.Values.ToList();

    Console.WriteLine("Cows  : " + beef.Count() + ".");
    Console.WriteLine("Steaks: " + beef.OfType<Steak>().Count() + ".");
    Console.WriteLine("Jerkys: " + beef.OfType<Jerky>().Count() + ".");
</code>```

Produces:

```<code>Cows  : 5.
Steak : 2.
Jerky : 2.
</code>```

Body:
I'm using Dapper and I am trying to produce a list with 3 classes, 2 inherited and a base class . These classes are:

public class Cow
{
    public int Id { get; set; }
    public string Name { get; set; }
}
public class Steak: Cow
{
    public int DonenessId { get; set; }
}
public class Jerky: Cow
{
    public int MarinadeId { get; set; }
}

My stored procedure doesn't have any parameters and uses left outer joins:

SELECT *  FROM Cow c
LEFT OUTER JOIN dbo.Jerky j ON j.CowId = c.Id
LEFT OUTER JOIN dbo.Steak s ON s.CowId = c.Id

=

+----+----------+------+-------+------------+------+-------+------------+
| Id | Name     | Id   | CowId | MarinadeId | Id   | CowId | DonenessId |
+-----------------------------------------------------------------------+
| 1  | Artricia | NULL | NULL  | NULL       | 21   |   1   | 5          |
+-----------------------------------------------------------------------+
| 2  | Betty    | 13   | 2     | 3          | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 3  | Cindy    | 14   | 3     | 1          | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 4  | Denile   | NULL | NULL  | NULL       | NULL | NULL  | NULL       |
+-----------------------------------------------------------------------+
| 5  | Enid     | NULL | NULL  | NULL       | 22   | 5     | 3          |
+----+----------+------+-------+------------+------+-------+------------+

I'm trying to produce a list of Cow objects so I can loop through them, I need to use Dapper for my organisation and I need it in one stored procedure.

From the above results I'm looking to achieve a list of 5 Cow Objects where 2 can be casted as Steak and 2 can be casted as Jerky.

Edit: Refined what I'm asking for.

I'm stuck because I don't know what to put in the map: argument of the query. Additionally should the type be , or ?

Body:
I have solved my problem, instead of deleting the question I'll leave the answer here because it took alot of bashing and i worked hard on this beef abstraction for y'all.

Firstly, the result set of the stored procedure has to have better names for the columns.

SELECT
c.Id AS Id,
c.Name AS Name,
j.Id AS JerkyId,
j.MarinadeId AS JerkyMarinadeId,
s.Id AS SteakId,
s.DonenessId AS SteakDonenessId
FROM Cow c
LEFT OUTER JOIN dbo.Jerky j ON j.CowId = c.Id
LEFT OUTER JOIN dbo.Steak s ON s.CowId = c.Id

Since there are now uniquely named columns which seperate the joins, we can splitOn:

var lookup = new Dictionary<int, Cow>();
_dbConnection.Query<Cow, Jerky, Steak, Cow>(QueryConstants.MeatDetective,
    (c, j, s) =>
    {
        Cow cow;
        if (!lookup.TryGetValue(c.Id, out cow))
        {
            if (s != null)
            {
                s.Id = c.Id;
                s.Name = c.Name;
                lookup.Add(c.Id, s);
            }
            else if (j != null)
            {
                j.Id = c.Id;
                j.Name = c.Name;
                lookup.Add(c.Id, j);
            }
            else
            {
                lookup.Add(c.Id, c);
            }
        }

        return cow;
    }, splitOn: "JerkyId,SteakId");
    var beef = lookup.Values.ToList();

    Console.WriteLine("Cows  : " + beef.Count() + ".");
    Console.WriteLine("Steaks: " + beef.OfType<Steak>().Count() + ".");
    Console.WriteLine("Jerkys: " + beef.OfType<Jerky>().Count() + ".");

Produces:

Cows  : 5.
Steak : 2.
Jerky : 2.