# Need SQL Code Changed To Python Code Equivalent

**URL:** <https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327>\
**Category:** General\
**Created:** [February 21, 2020, 9:19pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327 "2020-02-21T21:19:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddywinch82](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eddywinch82/32/134252_2.png) [@eddywinch82](https://forum.freecodecamp.org/u/eddywinch82)\
**Post date:** [February 21, 2020, 9:19pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/1 "2020-02-21T21:19:49Z")

</div>

Hi There,

I have the following SQL Code :-

```nohighlight
SELECT * INTO #Temp4
FROM
(
SELECT
tt5.[Venue],
tt5.[BID],
MIN(tt1.[Date]) AS [Date],
tt5.[Display / Flypast],
SUM(tt1.[Duration]) AS [Duration (mins)],
(SELECT DISTINCT '; ' + t5.[Aircraft Combined]
	FROM #Temp5 t5
	WHERE tt5.[Venue] = t5.[Venue]
	AND tt5.[BID] = t5.[BID]
	AND tt5.[Display / Flypast] = t5.[Display / Flypast]
	FOR XML PATH ('')) [Aircraft Combined],
SUM(tt5.[Dakota and Fighters in Same Slot?]) AS [Dakota and Fighters in Same Slot?]

```

Could someone please tell me, what the Python Code equivalent would be ?

Any help and info would be much appreciated.

Regards

Eddie Winch

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 21, 2020, 9:57pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/2 "2020-02-21T21:57:18Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

**Note:** Backticks are not single quotes.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [February 21, 2020, 10:21pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/4 "2020-02-21T22:21:50Z")

</div>

Wow, those column names. Horrifying.

---

<div class="post-metadata">

**Author:** ![eddywinch82](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eddywinch82/32/134252_2.png) [@eddywinch82](https://forum.freecodecamp.org/u/eddywinch82)\
**Post date:** [February 21, 2020, 10:22pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/5 "2020-02-21T22:22:11Z")

</div>

Hi Randall, many thanks for your reply.

I actually have a Python Code, using Pandas in Jupyter Notebook, getting a DataFrame from an. xls Excel File. but I have hit an issue, with the Code.

I have a friend who, is good with SQL Code, and he is trying to, to help me by writing Code in SQL, to do what I want. That particular part of the current Code, is significant to the issue I have. Could I post the full Python Code here ?

The issue I am talking about is covered in the following Link, on page 3 Of that Thread :-

> **[Filtering Excel Document Data Based On Numerical Values](https://python-forum.io/Thread-Filtering-Excel-Document-Data-Based-On-Numerical-Values?page=3)**
>
> Hi there,
> 
> I have a code Filtering Data, that I wan't displayed from an Excel Document using Pandas
> in Jupyter Notebook. It is for a UK RAF Historic Aircraft Display Team, Year 2009 Appearance Schedule.
> 
> Here is my Python Code :-
> 
> import pandas as...

Regards

Eddie Winch

---

<div class="post-metadata">

**Author:** ![becausealice2](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/becausealice2/32/84096_2.png) [@becausealice2](https://forum.freecodecamp.org/u/becausealice2)\
**Post date:** [February 22, 2020, 7:34pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/6 "2020-02-22T19:34:33Z")

</div>

I promise you that you don’t have to use them.

---

<div class="post-metadata">

**Author:** ![becausealice2](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/becausealice2/32/84096_2.png) [@becausealice2](https://forum.freecodecamp.org/u/becausealice2)\
**Post date:** [February 22, 2020, 7:36pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/7 "2020-02-22T19:36:15Z")

</div>

Have a look at [this Medium article](https://medium.com/jbennetcodes/how-to-rewrite-your-sql-queries-in-pandas-and-more-149d341fc53e) and see if it helps you resolve your issue.

---

<div class="post-metadata">

**Author:** ![eddywinch82](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eddywinch82/32/134252_2.png) [@eddywinch82](https://forum.freecodecamp.org/u/eddywinch82)\
**Post date:** [February 22, 2020, 7:53pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/8 "2020-02-22T19:53:24Z")

</div>

Hi Alice,

Many thanks for your reply, yes I will take a look at that article, thanks for posting it.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 7:35pm UTC](https://forum.freecodecamp.org/t/need-sql-code-changed-to-python-code-equivalent/352327/9 "2021-06-01T19:35:17Z")

</div>

Closed on June 1, 2021, 7:35pm UTC


