Home > database >  The great god help see, SQL which is wrong? With Oracle
The great god help see, SQL which is wrong? With Oracle

Time:09-26

The SELECT tu. User_name, NVL (SUM (FDS) MONEY), 0) MONEY
The FROM F_DRUG_SALES FDS
INNER JOIN T_USER_PROPERTY tu
ON the FDS. BILLING_PERSON_ID=tu. ID
INNER JOIN T_DATES td
ON the FDS. DATE_ID=td. ID
WHERE 1=1
AND the FDS. BILLING_OFFICE_ID IN (13287)
AND td. CAL_DATE & gt;
='2017-05-01'AND td. CAL_DATE & lt;
='2017-05-31'GROUP BY tu. User_name
The ORDER BY NVL (SUM (FDS) MONEY), 0) DESC
WHERE ROWNUM & lt;=10

CodePudding user response:

Nested layer, the select * from (your query) where rownum<=10

CodePudding user response:

Try this SQL
 
The select tu. User_name, NVL (sum (FDS) money), 0) money
The from f_drug_sales FDS
Inner join t_user_property tu
On the FDS. Billing_person_id=tu. Id
Inner join t_dates td
On the FDS. Date_id=td. Id
Where the FDS. Billing_office_id in (13287)
And td. Cal_date & gt;
='2017-05-01'And td. Cal_date & lt;
='2017-05-31'And rownum & lt;=10
Group by tu. User_name
The order by NVL (sum (FDS) money), 0) desc

CodePudding user response:

Adjust the:
 
The select user_name, money
The from (select tu user_name, NVL (sum (FDS) money), 0) money
The from f_drug_sales FDS
Inner join t_user_property tu
On the FDS. Billing_person_id=tu. Id
Inner join t_dates td
On the FDS. Date_id=td. Id
Where the FDS. Billing_office_id in (13287)
And td. Cal_date & gt;
='2017-05-01'And td. Cal_date & lt;
='2017-05-31'Group by tu. User_name
The order by NVL (sum (FDS) money), 0) desc
)
Where rownum & lt;=10

CodePudding user response:

refer to the second floor qq646748739 response:
try this SQL
 
The select tu. User_name, NVL (sum (FDS) money), 0) money
The from f_drug_sales FDS
Inner join t_user_property tu
On the FDS. Billing_person_id=tu. Id
Inner join t_dates td
On the FDS. Date_id=td. Id
Where the FDS. Billing_office_id in (13287)
And td. Cal_date & gt;
='2017-05-01'And td. Cal_date & lt;
='2017-05-31'And rownum & lt;=10
Group by tu. User_name
The order by NVL (sum (FDS) money), 0) desc


The original poster that is unlikely to be what you mean, this makes little sense to query

CodePudding user response:

Problem solved, building knot stick!
  • Related