SQL - I am trying to isolate or group each transaction by each cardholder and my code is below

Troy Draizen

The code runs ok when i don't have the last line (GROUP BY ch.name). When I include the line I receive an error listed below - I am trying to get a query where I can identify and group many things such as grouping transactions by cardholder and grouping from 7:00 - 9:00 AM EST. Still new to coding so a bit frustrated. Any help is appreciated!

ERROR: column "t.date" must appear in the GROUP BY clause or be used in an aggregate function

LINE 1: SELECT ch.name, t.date, t.amount, t.card AS "Credit Card", t...
^
SQL state: 42803
Character: 17

My query:

SELECT 
    ch.name, t.date, t.amount, t.card AS "Credit Card", t.id_merchant,
    m.name AS "Merchan, mc.name AS "merchant category"
FROM
    transaction AS t
JOIN 
    credit_card AS cc ON (t.card = cc.card)
JOIN 
    card_holder AS ch ON (cc.cardholder_id = ch.id)
JOIN 
    merchant AS m ON (t.id_merchant = m.id)
JOIN 
    merchant_category AS mc ON (m.id_merchant_category = mc.id)
GROUP BY 
    ch.name;
lion_pankaj
SELECT ch.name, t.date, t.amount, t.card AS "Credit Card", t.id_merchant, m.name AS "Merchan mc.name AS "merchant category" 
FROM transaction AS t 
JOIN credit_card AS cc ON (t.card = cc.card) 
JOIN card_holder AS ch ON (cc.cardholder_id = ch.id) 
JOIN merchant AS m ON (t.id_merchant = m.id) 
JOIN merchant_category AS mc ON (m.id_merchant_category = mc.id) 
GROUP BY (ch.name, t.date, t.amount, t.card, t.id_merchant, m.name, mc.name);

Try above.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am trying to use SQL to count the number of rows for each date in my database

How can i fix my code to put each paragraph in a new line, as I am trying to add paragraph before the given paragraph

i am trying to create foreign keys but i got error 1822 .. please see my code below

I am trying to export an excel and make it password protected. My code is given below.But i am getting error

I am trying to find the original index value of the last occurence of each group

I am trying to use awk to extract a portion of each line in my file

I am trying to add one to each digit in my problem but I am getting a syntax error that doesn't make sense?

I am trying to write a Python code that reads each item in a list and add and find the average of that list with certain conditions

I am trying create a button in which boolean function should be performed. below is my view code. Can anyone help me

I am trying to write a simple smart contract in remix ide and getting encountered by a generic error again and again. Below is my code and error

i am not getting an output of reversed array from my code below

I am trying to click on each link using selenium and python

I am trying to retrieve results from two for each loops

I am trying to have the number of threads requested print through each pass of my for loop in the thread_func call

How do I make animation play after each 'game over/restart' status and not only once(as showin in my code below)?

sql - order by for each group

SQL iterate for each group

Spider Kernel is dying each time whenever I am running this code

Why am I getting 32767 after each output in the following code?

I am trying to know the reason my code is not running

I'm trying to center text within each of my grid cells

How can I solve the error message I am receiving in my below code in my policy documents

Sql group by sum of each group

I am trying to upload the captured/ selected image from gallery to my server but it is giving below error

SQL How to add new columns each time I run my code

I am trying to learn triggers on my sql and getting the following errors

JS + HTML: Im trying to use the for in or the for each loop instead of the default for loop in my code. But i can`t get it working

I am trying to wrap my head around below elasticsearch dsl. Can someone tell me how `must` clause is used below

I am trying to access the data stored in a snowflake table using python sql. Below is the columns given below i want to access