Skip to content
Advertisement

Tag: mysql

MYSQL getting data from three tables

I am trying to find the drinker and total amount of money spent on drinks for all drinkers in February 2020. I also need to include drinkers who haven’t ordered a drink in this period. Here are the three tables: Here is my statement so far: I am very new to SQL, I know that there are a number of

MySQL: Counting active products that belong to active categories (and optionally to active subcategories)

i’m using MySQL 5.6. I need to get a list of categories, with a product count column. So far, a very easy and trivial task. Here’s where it gets a little complicated: A product has a category, and can also have a subcategory (optionally). Categories, subcategories and products can be active (flg_public=1) or disabled (flg_public=NULL). So, the query should return

SQL Combine two queries and SUM

Ok I am a little rusty in SQL. I have 2 exactly same tables with columns ID, Name, Gender, BG. BG is a internal reference. I can query each table individually: SELECT Gender,BG, COUNT(BG) CountValue …

How to calculate AVG, MIN & MAX of date interval of a column in a table?

I have a table more like this +—-+————-+———————+ | id | order_id | transaction_date | +—-+————-+———————+ | 1 | TEST000001 | 2018-01-01 00:00:10 | | 2 | TEST000002 | 2018-01-01 00:10:10 | | 3 | TEST000003 | 2018-01-02 03:18:01 | | 4 | TEST000004 | 2018-02-04 05:00:00 | | 5 | TEST000005 | 2018-02-10 16:00:10 | +—-+————-+———————+ There is datetime

Advertisement